Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(async_await)]
- extern crate futures;
- use {
- futures::{
- future::{FutureExt, BoxFuture},
- task::{ArcWake, waker_ref},
- },
- std::{
- future::Future,
- sync::{Arc, Mutex},
- sync::mpsc::{sync_channel, SyncSender, Receiver},
- task::{Context, Poll},
- time::Duration,
- },
- };
- // Async proccesses
- struct WaitingForGodotTask {
- future: Mutex<Option<BoxFuture<()>>>,
- task_sender: SyncSender<Arc<WaitingForGodotTask>>,
- }
- #[derive(Debug)]
- struct Godot;
- impl Godot { async fn new() -> Godot { let g = Godot{}; loop {}; g } }
- impl Default for Godot { fn default() -> Self { Godot{} } }
- impl Future for Godot {
- type Output = Self;
- fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
- if true { Poll::Pending } else { Poll::Ready(Godot::default()) }
- }
- }
- // Runtime
- #[derive(Debug)]
- struct MadamExecutioner { recvs: Receiver<Arc<WaitingForGodotTask>> }
- impl MadamExecutioner {
- fn run(&self) {
- futures::executor::spawn(move|| {
- async { Godot::new(); };
- });
- }
- }
- #[derive(Clone)]
- struct Spawner { task_sender: SyncSender<Arc<WaitingForGodotTask>>, }
- impl ArcWake for WaitingForGodotTask {
- fn wake_by_ref(arc_self: &Arc<Self>) {
- // Implement `wake` by sending this task back onto the task channel
- // so that it will be polled again by the executor.
- let cloned = arc_self.clone();
- arc_self.task_sender.send(cloned).expect("too many tasks queued");
- }
- }
- fn main() {
- let (task_sender, ready_queue) = sync_channel(5);
- let me = MadamExecutioner { recvs: ready_queue };
- dbg!(me);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement