Comments (6)
Rust's documentation seems to imply that a panic is the preferred option in this case.
from event-listener.
It seems you are using the future like this:
let mut listener = event.listen();
loop {
if 0 == n.load(Ordering::SeqCst) {
return Poll::Ready(());
};
ready!(Pin::new(&mut listener).poll(cx));
}
It should be used like this:
let mut listener = None;
loop {
if 0 == n.load(Ordering::SeqCst) {
return Poll::Ready(());
};
if let Some(listener) = listener.as_mut() {
ready!(Pin::new(&mut listener).poll(cx));
listener = None;
} else {
listener = Some(event.listen());
}
}
Polling the EventListener
after it has returned Ready
will panic, and further polls should use a completely new EventListener
instead.
The v4 API kept track of this state inside of the EventListener,
but this caused confusion and was removed in v5.
from event-listener.
If you think this could be made clearer in documentation I would accept a PR.
from event-listener.
Would it make sense to just always return ready once it has ever been ready instead of panicking? That seems a lot easier to document and explain.
from event-listener.
It looks like EventListener holds an InnerListener that contains a reference to the Event. Would it work to have a configurable option that allows the listener to reregister itself on completion? It feels awkward to require user code to match Pin::new(&mut listener).poll(cx) { Poll::Ready(()) => { *listener = event.listen(); ... }, ... }
from event-listener.
It's a bad idea to have the EventListener
automatically insert itself into the list. Generally, the flow should be:
- Check your condition.
- Register the listener into the list.
- Check your condition, ideally with stronger ordering.
- Wait on the listener.
If you register the listener into the list without actively polling an event, it can lead to strange behavior. E.g. your future received a notification meant for another task
from event-listener.
Related Issues (20)
- Unsoundness HOT 11
- RFC: Less complex, footgun free API HOT 2
- expose listener count HOT 4
- Remove concurrent-queue dependency
- `NonBlocking` doesn't implement `Send` and `Sync` HOT 2
- Possible racecondition HOT 1
- Question about new API HOT 3
- Miri reports a deadlock in `async-lock` HOT 2
- During racy initialization, a race can happen where a notification is dropped HOT 2
- Is `Event::notify(usize::MAX)` signal safe? HOT 4
- Loosen concurrent-queue dependency HOT 2
- This seems actually not stable(Dead lock) HOT 5
- fmt::Debug should produce actually useful output
- Split event-listener-strategy out into a new crate HOT 2
- Miri test failure with --no-default-features HOT 1
- EventListener::new footgun HOT 1
- Remove EventListener::new footgun HOT 6
- `EventListener` doesn't implement `UnwindSafe` HOT 1
- wasm test failed with "index out of bounds: the len is 0 but the index is 4" HOT 6
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 event-listener.