rename method from read_all_from_stream_async to move_all_from_stream_async, change arguments order, update comments

This commit is contained in:
yggverse 2024-12-09 14:00:35 +02:00
parent 6ac26bad62
commit 059fa8f2d7

View file

@ -22,9 +22,9 @@ pub fn from_stream_async(
on_chunk: impl Fn((Bytes, usize)) + 'static, on_chunk: impl Fn((Bytes, usize)) + 'static,
on_complete: impl FnOnce(Result<MemoryInputStream, Error>) + 'static, on_complete: impl FnOnce(Result<MemoryInputStream, Error>) + 'static,
) { ) {
read_all_from_stream_async( move_all_from_stream_async(
MemoryInputStream::new(),
base_io_stream, base_io_stream,
MemoryInputStream::new(),
cancelable, cancelable,
priority, priority,
(bytes_in_chunk, bytes_total_limit, 0), (bytes_in_chunk, bytes_total_limit, 0),
@ -32,18 +32,22 @@ pub fn from_stream_async(
); );
} }
/// Asynchronously read entire [InputStream](https://docs.gtk.org/gio/class.InputStream.html) /// Asynchronously move all bytes from [IOStream](https://docs.gtk.org/gio/class.IOStream.html)
/// from [IOStream](https://docs.gtk.org/gio/class.IOStream.html) /// to [MemoryInputStream](https://docs.gtk.org/gio/class.MemoryInputStream.html)
/// * require `IOStream` reference to keep `Connection` active in async thread /// * require `IOStream` reference to keep `Connection` active in async thread
pub fn read_all_from_stream_async( pub fn move_all_from_stream_async(
memory_input_stream: MemoryInputStream,
base_io_stream: impl IsA<IOStream>, base_io_stream: impl IsA<IOStream>,
cancelable: Cancellable, memory_input_stream: MemoryInputStream,
cancellable: Cancellable,
priority: Priority, priority: Priority,
bytes: (usize, usize, usize), bytes: (
usize, // bytes_in_chunk
usize, // bytes_total_limit
usize, // bytes_total
),
callback: ( callback: (
impl Fn((Bytes, usize)) + 'static, impl Fn((Bytes, usize)) + 'static, // on_chunk
impl FnOnce(Result<MemoryInputStream, Error>) + 'static, impl FnOnce(Result<MemoryInputStream, Error>) + 'static, // on_complete
), ),
) { ) {
let (on_chunk, on_complete) = callback; let (on_chunk, on_complete) = callback;
@ -52,7 +56,7 @@ pub fn read_all_from_stream_async(
base_io_stream.input_stream().read_bytes_async( base_io_stream.input_stream().read_bytes_async(
bytes_in_chunk, bytes_in_chunk,
priority, priority,
Some(&cancelable.clone()), Some(&cancellable.clone()),
move |result| match result { move |result| match result {
Ok(bytes) => { Ok(bytes) => {
// Update bytes total // Update bytes total
@ -75,10 +79,10 @@ pub fn read_all_from_stream_async(
memory_input_stream.add_bytes(&bytes); memory_input_stream.add_bytes(&bytes);
// Continue // Continue
read_all_from_stream_async( move_all_from_stream_async(
memory_input_stream,
base_io_stream, base_io_stream,
cancelable, memory_input_stream,
cancellable,
priority, priority,
(bytes_in_chunk, bytes_total_limit, bytes_total), (bytes_in_chunk, bytes_total_limit, bytes_total),
(on_chunk, on_complete), (on_chunk, on_complete),