A minor variation on a LocalPool executor which exposes unique IDs for tracking future completion.
This should almost be a drop in replacement for the existing LocalPool. All existing traits are still implemented. There are two API differences:
1. New (Local)SpawnWithId
traits have been implemented. These accept the same arguments as their non-ID counterparts but return a unique ID that can be used to identify whether a spawned future has been completed.
2. try_run_one
now returns an Option<usize>
instead of a boolean. This usize will correspond to the ID received from the previous APIs and can be used with external tracking mechanism to know if a future is complete.
```rust let mut spawned_ids = std::collections::HashSet::new(); let mut pool = LocalPool::new(); let spawner = pool.spawner();
let (id1, handle1) = spawner .spawnwithhandle(futures::future::ready(1i32)) .unwrap(); let (id2, handle2) = spawner .spawnwithhandle(futures::future::ready(2u32)) .unwrap();
spawnedids.insert(id1); spawnedids.insert(id2);
while !spawnedids.isempty() { if let Some(completed) = pool.tryrunone() { assert!(spawned_ids.remove(&completed)) } }
asserteq!(handle1.nowornever().unwrap(), 1); asserteq!(handle2.nowornever().unwrap(), 2); ```