mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-30 00:00:16 +02:00
Add a &LoopPin to add_loop_data closures
This way they can use that proof that they're running on the event loop
This commit is contained in:
@@ -95,7 +95,7 @@ impl LoopHandle {
|
|||||||
/// closure `f`, generate a handle, and then the future will yield it back.
|
/// closure `f`, generate a handle, and then the future will yield it back.
|
||||||
// TODO: more with examples
|
// TODO: more with examples
|
||||||
pub fn add_loop_data<F, A>(&self, f: F) -> AddLoopData<F, A>
|
pub fn add_loop_data<F, A>(&self, f: F) -> AddLoopData<F, A>
|
||||||
where F: FnOnce() -> A + Send + 'static,
|
where F: FnOnce(&LoopPin) -> A + Send + 'static,
|
||||||
A: 'static,
|
A: 'static,
|
||||||
{
|
{
|
||||||
AddLoopData {
|
AddLoopData {
|
||||||
@@ -109,18 +109,19 @@ impl LoopHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<F, A> Future for AddLoopData<F, A>
|
impl<F, A> Future for AddLoopData<F, A>
|
||||||
where F: FnOnce() -> A + Send + 'static,
|
where F: FnOnce(&LoopPin) -> A + Send + 'static,
|
||||||
A: 'static,
|
A: 'static,
|
||||||
{
|
{
|
||||||
type Item = LoopData<A>;
|
type Item = LoopData<A>;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<LoopData<A>, io::Error> {
|
fn poll(&mut self) -> Poll<LoopData<A>, io::Error> {
|
||||||
let ret = self.inner.poll(|_lp, f| {
|
let ret = self.inner.poll(|lp, f| {
|
||||||
Ok(DropBox::new(f()))
|
Ok(DropBox::new(f(&lp.pin())))
|
||||||
}, |f, slot| {
|
}, |f, slot| {
|
||||||
Message::Run(Box::new(move || {
|
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");
|
.expect("add loop data try_produce intereference");
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user