# tokio-blocking
A thin wrapper to provide a simple interface to insert blocking operations between non-blocking operations in the context of futures.
```rust
let mut runtime = Runtime::new().unwrap();
let pool = ThreadPool::new(4);
let task = lazy(|| Ok::<_, ()>(3))
.and_then(|_| {
// Normal non-blocking operations
Ok(())
})
.and_then_block(pool, move |_| {
// Allow blocking operation, which doesn't actually block other futures
std::thread::sleep(std::time::Duration::from_secs(3));
Ok(10)
})
.and_then(|_| {
// Normal non-blocking operation
Ok(())
});
runtime.block_on(task).unwrap();
```
This crate was born because the existing [blocking](https://docs.rs/tokio-threadpool/0.1.10/tokio_threadpool/fn.blocking.html):
1. requires much boilerplate.
2. blocks the entire task after all (e.g. `select` doesn't work well).
### Combinators
The following combinators are supported. All of them takes two arguments: one is the handle of the thread pool which takes care of the blocking operation
, and the other is the callback to be called after the blocking operation gets completed. The type of the return value of the callback is `Result`.
It's passed to to the subsequent combinators as the normal combinators (such as `and_then`) do.
1. `and_then_block`
2. `or_else_block`
3. `then_block`