Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit d438334

Browse files
committed
Implement futures-0.3 Spawn for &MainContext
This allows to use `MainContext` as a futures-0.1 `Executor` with the help of the futures-0.1 compatibility layer
1 parent c5e2632 commit d438334

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main_context_futures.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ impl MainContext {
335335
}
336336

337337
impl Spawn for MainContext {
338+
fn spawn_obj(&mut self, f: FutureObj<'static, ()>) -> Result<(), SpawnError> {
339+
(&*self).spawn_obj(f)
340+
}
341+
}
342+
343+
/// Implementing `Spawn` for a _reference_ of `MainContext` allows to convert it to a futures-0.1 `Executor`,
344+
/// using the futures-0.1 compatibility layer.
345+
///
346+
/// See https://rust-lang-nursery.github.io/futures-api-docs/0.3.0-alpha.16/src/futures_util/compat/executor.rs.html#85
347+
impl Spawn for &MainContext {
338348
fn spawn_obj(&mut self, f: FutureObj<'static, ()>) -> Result<(), SpawnError> {
339349
let source = TaskSource::new(::PRIORITY_DEFAULT, None, f);
340350
source.attach(Some(&*self));

0 commit comments

Comments
 (0)