Skip to content

try_tick does not reschedule tasks #158

@MageSlayer

Description

@MageSlayer

Hi

I'd like to clarify the difference between tick and try_tick behavior.

I have a classical "external event loop" problem.
That's I need to drive my futures manually without blocking.

Currently I use following code (simplified):

pub struct LocalRuntimeTick {
    rt: LocalRuntime, // Tokio local runtime
    ex: LocalExecutor<'static>,
}

impl LocalRuntimeTick {
    fn new() -> Self {
        Self {
            rt: LocalRuntime::new().unwrap(),
            ex: LocalExecutor::new(),
        }
    }

    pub fn tick(&self, n: usize) -> bool {
        // "n" steps to tick
        let _guard = self.rt.enter();

        // "incremental" ticking
        self.rt.block_on(async {
            let mut r = false;
            for _i in 0..n {
                let t = self.ex.try_tick();
                if !t {
                    break;
                }
                r |= t;
            }
            r
        })
        // "incremental" ticking using tick
        //self.rt.block_on(async {
        //    let mut r = false;
        //    for _i in 0..n {
        //        if self.ex.is_empty() {
        //            break;
        //        }
        //        self.ex.tick().await;
        //        r = true;
        //    }
        //    r
        //})

        // wait and tick
        //self.rt.block_on(self.ex.tick());
        //true
    }
}

... and use something like ex.tick(2000); to push my futures.

Unfortunately my "incremental" tick does not work. My futures are scheduled just once and never after. "wait and tick" approach works, but blocks if no futures spawned.

I think I'm missing something important :)
Please help.

UPDATE.
My "incremental" ticking using .tick does not work either. It also blocks on missing futures...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions