From e71d509fee767d6b796ba18a5501f80f0fb4babc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 24 Aug 2016 18:44:04 -0700 Subject: [PATCH] Add a `&LoopPin` to `add_loop_data` closures This way they can use that proof that they're running on the event loop --- src/event_loop/loop_data.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/event_loop/loop_data.rs b/src/event_loop/loop_data.rs index 28086d4fd..1236b0df6 100644 --- a/src/event_loop/loop_data.rs +++ b/src/event_loop/loop_data.rs @@ -95,7 +95,7 @@ impl LoopHandle { /// closure `f`, generate a handle, and then the future will yield it back. // TODO: more with examples pub fn add_loop_data(&self, f: F) -> AddLoopData - where F: FnOnce() -> A + Send + 'static, + where F: FnOnce(&LoopPin) -> A + Send + 'static, A: 'static, { AddLoopData { @@ -109,18 +109,19 @@ impl LoopHandle { } impl Future for AddLoopData - where F: FnOnce() -> A + Send + 'static, + where F: FnOnce(&LoopPin) -> A + Send + 'static, A: 'static, { type Item = LoopData; type Error = io::Error; fn poll(&mut self) -> Poll, io::Error> { - let ret = self.inner.poll(|_lp, f| { - Ok(DropBox::new(f())) + let ret = self.inner.poll(|lp, f| { + Ok(DropBox::new(f(&lp.pin()))) }, |f, slot| { Message::Run(Box::new(move || { - slot.try_produce(Ok(DropBox::new(f()))).ok() + let pin = super::CURRENT_LOOP.with(|lp| lp.pin()); + slot.try_produce(Ok(DropBox::new(f(&pin)))).ok() .expect("add loop data try_produce intereference"); })) });