Park trait, ParkThread implementation and using it in LocalPool #1668
+325
−104
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I think it would be good to have a
Park
abstration (like the one in tokio) infutures-executor
(this has already been proposed and merged in #665 for the tokio-reform branch, which has been abonded in #645).In #665
Park
was renamed toSleep
, but I thinkPark
is the better choice:std
lib providesthread::park
for a sleeping mechanism that can be cancelled ("unparked").Apart from the names
Sleep
from #665 is basically the same as tokioPark
; further changes to the API (compared to tokio):Park::park_timeout
intoPark::park
, now taking aParkDuration
enum: most implementations I've seen used shared code anyway.Park::park
now also includes a&mut Enter
argumentUnpark
trait,Park
no longer has an associatedUnpark
type. Usingfutures_util::task::WakerRef
instead for the result of thewaker
function (renamed fromunpark
).I think reusing the
Waker
abstraction is rather obvious; but there are probably two open questions:Waker
instead ofWakerRef
?ParkDuration::Poll
and interpret a zero duration inParkDuration::Duration(..)
as "poll only but don't yield"?This pull request also contains a
ParkThread
implementation ofPark
(based onstd::thread::park
and similar to whatLocalPool
was using) and supports usingLocalPool
with customPark
implentations (defaulting toParkThread
). This wayLocalPool
can be combined into a "local-thread runtime" with a timer and a reactor.References:
tokio_executor::park
std::thread::park