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

Commit 94bbc9f

Browse files
authored
Merge pull request #498 from njam/futures01-executor
Implement futures-0.3 `Spawn` for `&MainContext`
2 parents c5e2632 + d438334 commit 94bbc9f

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)