Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose mio::Handler.tick #17

Open
seanmonstar opened this issue Feb 26, 2016 · 1 comment
Open

Expose mio::Handler.tick #17

seanmonstar opened this issue Feb 26, 2016 · 1 comment

Comments

@seanmonstar
Copy link
Contributor

Besides for some debugging purposes, (such as seeing how many ticks occurring before my other code wakes the socket up again), this would also be useful for the Machine to be able to notify a user if they are doing blocking work, or otherwise too much work, in the ready event. One could observe the time difference between ticks, and above a threshold, act accordingly.

@tailhook
Copy link
Owner

Well, I'm okay with exposing tick, but I'm not sure about the API's. There are now global events in rotor yet. But for your use case:

this would also be useful for the Machine to be able to notify a user if they are doing blocking work, or otherwise too much work, in the ready event. One could observe the time difference between ticks, and above a threshold, act accordingly.

The tick event is inherently global (for all state machines). To observe ready events for your state machine you may just write a wrapper type:

struct TickMeasure<M>(M);

impl<M> Machine for TickMeasure<M> {
    fn ready(...) {
        let tm = get_time();
        let res = self.0.ready(...);
        println!("time {:?}", get_time() - tm);
        return res;
    }
}

Then you can wrap any state machine into this type. Surely, you can wrap every state machine with it, just measurements will be individual (comparing to EventLoop::tick())

You can also submit a pull request to rotor-tools if you think such utility is generally useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants