From a142eb2d3f86ae0e4394399e995c9fef9e6b8a0e Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 6 Nov 2018 21:44:24 -0600 Subject: [PATCH] Check for new jobs when a job has been returned --- jobs-tokio/src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jobs-tokio/src/lib.rs b/jobs-tokio/src/lib.rs index 708fc51..0f41f6e 100644 --- a/jobs-tokio/src/lib.rs +++ b/jobs-tokio/src/lib.rs @@ -127,12 +127,22 @@ fn process_jobs( .fold( (processors, num_processors), move |(processors, processor_count), msg| match msg { - ProcessorMessage::Job(job) => Either::A(return_job( - storage.clone(), - processor_count, - processors, - job, - )), + ProcessorMessage::Job(job) => { + let tx = tx.clone(); + + Either::A( + return_job(storage.clone(), processor_count, processors, job).map( + move |values| { + tokio::spawn( + tx.send(ProcessorMessage::Time(tokio::clock::now())) + .map(|_| ()) + .map_err(|_| ()), + ); + values + }, + ), + ) + } ProcessorMessage::Time(_) => Either::B(Either::A(try_process_job( storage.clone(), processor_count,