Comments (1)
When merging N streams, we can either
- poll each of them every time, or
- poll only the ones that have are ready to be polled.
We go with the second approach (because when N is huge, the first can become quite slow).
This requires keeping track of which streams are ready to be polled. Each stream tell us that it is ready by waking the waker we passed to it when we polled it last time. So when one of our wakers is woken, we need to record that the associated stream is ready to be polled again.
The way Rust's async is designed, wakers can be woken from anywhere at anytime. It doesn't matter what is going on with the Merge
; one stream might have sent a waker to a different thread and that thread can wake it at will.
So the state where we record streams' readiness needs to be accessible from any thread at anytime. Hence the Mutex.
That said, the Mutex is not absolutely required; we can switch WakerArray from having an array of bool
inside a Mutex to using an array of AtomicBool
.
PR #115, will make things harder (as WakerArray will then contain a list of woken futures/streams), but even then avoiding Mutex is still possible by use of a non-blocking linked list or something similar.
from futures-concurrency.
Related Issues (20)
- Fair chaining APIs HOT 4
- Governance while yosh is out of office HOT 2
- Implement PinnedDrop for `impl RaceOk for Tuple` HOT 2
- Explain difference between https://github.com/rust-lang/futures-rs HOT 1
- Stream `merge` function calls `poll_next` again after returning `Poll::Ready(None)` HOT 7
- Sould futures in `Join` be dropped at completion of each? HOT 3
- Proposal: add `stream::Race` HOT 1
- Fix bounds on `impl {Chain,Zip} for tuple` HOT 1
- Add `try_join` and `race_ok` methods to `FutureExt`
- TryJoin2 polls completed futures HOT 5
- `tracing` can't track the execution duration of futures passed to `futures-concurrency`
- Where is `TryMerge` :-)? HOT 2
- Add a `StreamSet` API HOT 1
- How should I factor my specific problem, and more broadly, how should I handle `Result<!, E>`? HOT 2
- Using .join() on an empty Vec stalls HOT 2
- `TryJoin` on tuple trying to free a null pointer HOT 8
- wrapping_rem called with a value of zero HOT 4
- Handling control flow HOT 2
- Improve error handling `race_ok` variants HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from futures-concurrency.