Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Task::is_notified()? #757

Closed
jsgf opened this issue Nov 16, 2018 · 3 comments
Closed

Implement Task::is_notified()? #757

jsgf opened this issue Nov 16, 2018 · 3 comments

Comments

@jsgf
Copy link

jsgf commented Nov 16, 2018

Version

tokio 0.1.11

Platform

Linux x86-64

Subcrates

Description

I'm writing some low-level code which directly uses Task, task::current() and Task::notify(). I the code I'm currently dealing with, I have a queue of Tasks which are awaiting notification. Sometime a task will remove itself from that queue because its no longer interested in the event. The problem is that it may have picked up a notification which isn't going to use, but some other task on that queue does need to make progress.
At the moment, when it withdraws from the queue it just unconditionally notifies some other task on the queue to make sure there's progress. But it would be better if it could see if there's a pending notification and only then pass it on to a queued task.

Is there a way to do this in the current API? Failing that, would it make sense to add Task::is_notified() or equivalent?

@tobz
Copy link
Member

tobz commented Nov 16, 2018

Could you do this with a queue of oneshots?

Have your subscribers hold the receiver, and when they're no longer interested, simply drop it. You can detect that condition when you go to "send" your "notification" to the subscriber, giving you the chance to grab the next subscriber from the list.

@carllerche
Copy link
Member

I’m not exactly following the problem tbh. What is stopping you from teaching is notified yourself in the queue?

@jsgf
Copy link
Author

jsgf commented Nov 24, 2018

Yeah, it doesn't really help because there's always a window between calling it and actually dropping the Task. An external flag would work just as well since it needs extra coordination to make sure the wakeup isn't dropped.

@jsgf jsgf closed this as completed Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants