threefoldtech / rmb-rs

RMB implementation in rust
Apache License 2.0
3 stars 1 forks source link

worker pool graceful shutdown and cancellation #24

Closed muhamadazmy closed 1 year ago

muhamadazmy commented 2 years ago

Currently on shutting down a pool, there is a noway to wait for workers who are currently doing work. This can result of loss of work (progress or data). Hence in a "complete" workers pool, some cancellation mechanism need to be implemented.

By default, with current implementation on Pool drop, the workers will automatically shutdown because the channel will be dropped. This is correct and good to have. But a user of the pool might also want to make sure that all workers have done doing their work before dropping the pool.

Hence a new method Pool.close() function is needed that is basically going to stop the pool, close the channel and then wait for all workers to finish and return before returning. This means the user of the pool can either choose to just drop the pool and not care about workers if they are finished or not. or call close to make sure all workers are finished before returning.