Created
October 23, 2012 21:03
-
-
Save brson/3941542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let (spawn_chan, spawn_port) = pipes::stream(); | |
// Create a 'spawn service' on this scheduler | |
do spawn |move spawn_port| { | |
loop { | |
let next_spawnee = spawn_port.recv(); | |
spawn(next_spawnee); | |
} | |
} | |
// Create a spawn function that forwards spawn requests back to this scheduler | |
let spawn_on_original_sched: ~fn(~fn()) = |f, move spawn_chan| { | |
spawn_chan.send(f); | |
}; | |
// Go do things in a different scheduler | |
do task().sched_mode(SingleThreaded).spawn |move spawn_on_original_sched| { | |
// Spawn onto the original scheduler | |
do spawn_on_original_sched { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment