Comments (1)
@eholk thanks for opening this!
I think you're correctly pointing out that fairness and non-determinism are not the same, and don't need to be implemented through the same mechanism. While we may want fairness, non-determinism comes at a cost.
Also, determinism is somewhat in conflict with fairness. If we did something like
[ready(1), ready(2), ready(3)].race()
then by our intuitive definition of fairness we should expect to get either 1, 2, or 3 out. But any deterministic scheduler will always return the same answer. So a deterministic scheduler can only be fair in the long run, but not for short-lived processes.
This to me is quite interesting! - To me the example you used is pretty much the "perfect" counter-example, and most cases wouldn't quite be like this. In practice it seems rare to expect someone to explicitly race two synchronous operations. In the case someone races 1 async + 1 sync operation, we already deterministically know that the synchronous one will complete before the async one. So the poll ordering practically doesn't matter.
The main example I'm thinking of is: we want to ensure that if we have a set of iterators, one iterator isn't starved before the other. We don't want Merge
to accidentally provide Chain
semantics when operating on non-async sequences. But as you say, we can trivially guarantee that by simply doing a round-robin iteration. [repeat(1), repeat(2), repeat(3)].merge()
would then always yield 1, 2, 3, 1, 2, 3, 1, 2, 3
. Which is fair and also deterministic.
Conclusion
I'm on board with this change ✅. Probably for the implementation it'd be nice if we could create a shared Indexer
struct or something which replaces the current RandomGenerator
and just cycles through the starting index. Basically the same semantics as (1..N).cycle()
- but as a separate struct.
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
- Possibly unnecessary use of `Mutex` in `Merge` implementation? 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.