pub fn new<Writer>(
        mut file: Writer,
        mut error_callback: Option<Box<dyn FnMut(std::io::Error) + Send>>
    ) -> Self
    where
        Writer: std::io::Write + Send + 'static
    {
        let (tasks_sender, task_receiver) = channel();

        let join_handle = Some(spawn(move || 'thread_loop: loop {
            let task = task_receiver.recv()
                .unwrap_or_else(|err| unreachable!(err)); // unreachable because owner thread will join this thread handle after send FileWorkerTask::Stop and only after will disconnect channel

            match task {
                FileWorkerTask::WriteString(data) => {
                    if let Err(err) = file.write_all(data.as_bytes()) {
                        if let Some(callback) = &mut error_callback { callback(err); }
                    }
                },
                FileWorkerTask::WriteBytes(data) => {
                    if let Err(err) = file.write_all(&data) {
                        if let Some(callback) = &mut error_callback { callback(err); }
                    }
                },
                FileWorkerTask::Stop => {
                    break 'thread_loop;
                },
            }
        }));

        FileWorker { task_sender: tasks_sender, join_handle }
    }
/// Constructs 'FileWorker' for write to the file in background thread.
/// Writes in the order of queue.
/// Parameter 'file' is opened and exclusive locked file.
/// Parameter 'error_callback' callback for receive errors or writing to the file.
Constructs 'FileWorker' for write to the file in background thread.
Writes in the order of queue.
Parameter 'file' is opened and exclusive locked file.
Parameter 'error_callback' callback for receive errors or writing to the file.
Constructs ' FileWorker ' for write to the file in background thread . Writes in the order of queue . Parameter ' file ' is opened and exclusive locked file . Parameter ' error_callback ' callback for receive errors or writing to the file .
pub fn new<Writer>(
        mut file: Writer,
        mut error_callback: Option<Box<dyn FnMut(std::io::Error) + Send>>
    ) -> Self
    where
        Writer: std::io::Write + Send + 'static
    {
        let (tasks_sender, task_receiver) = channel();
        let join_handle = Some(spawn(move || 'thread_loop: loop {
            let task = task_receiver.recv()
                .unwrap_or_else(|err| unreachable!(err)); // unreachable because owner thread will join this thread handle after send FileWorkerTask::Stop and only after will disconnect channel
            match task {
                FileWorkerTask::WriteString(data) => {
                    if let Err(err) = file.write_all(data.as_bytes()) {
                        if let Some(callback) = &mut error_callback { callback(err); }
                    }
                },
                FileWorkerTask::WriteBytes(data) => {
                    if let Err(err) = file.write_all(&data) {
                        if let Some(callback) = &mut error_callback { callback(err); }
                    }
                },
                FileWorkerTask::Stop => {
                    break 'thread_loop;
                },
            }
        }));
        FileWorker { task_sender: tasks_sender, join_handle }
    }
pub fn new < Writer > ( mut file : Writer , mut error_callback : Option < Box < dyn FnMut ( std :: io :: Error ) + Send > > ) -> Self where Writer : std :: io :: Write + Send + ' static { let ( tasks_sender , task_receiver ) = channel ( ) ; let join_handle = Some ( spawn ( move | | ' thread_loop : loop { let task = task_receiver . recv ( ) . unwrap_or_else ( | err | unreachable ! ( err ) ) ; // unreachable because owner thread will join this thread handle after send FileWorkerTask::Stop and only after will disconnect channel match task { FileWorkerTask :: WriteString ( data ) => { if let Err ( err ) = file . write_all ( data . as_bytes ( ) ) { if let Some ( callback ) = & mut error_callback { callback ( err ) ; } } } , FileWorkerTask :: WriteBytes ( data ) => { if let Err ( err ) = file . write_all ( & data ) { if let Some ( callback ) = & mut error_callback { callback ( err ) ; } } } , FileWorkerTask :: Stop => { break ' thread_loop ; } , } } ) ) ; FileWorker { task_sender : tasks_sender , join_handle } }
Constructs 'FileWorker' for write to the file in background thread.
Constructs ' FileWorker ' for write to the file in background thread .
file
Writer
error_callback
Option<Box<dyn FnMut(std::io::Error) + Send>>
file
Writer
error_callback
Option<Box<dyn FnMut(std::io::Error) + Send>>