tailhook / rotor

The mio-based framework for rust for doing I/O in simple and composable way (ABANDONED)
MIT License
361 stars 25 forks source link

How to wakeup a protocol? #3

Closed erikjohnston closed 8 years ago

erikjohnston commented 8 years ago

Reading the code it appears that to wake a protocol/event machine/thing up I need to know its associated mio::Token, however that doesn't seem to be exposed anywhere. Is this possible to do currently?

tailhook commented 8 years ago

Well, this is something half-baked. You need to know the token, but I don't want to expose token directly. I want some kind of Future object, that can be used to send the messages.

The problem with exposing token is that it is reused very fast in the current Slab implementation. I.e. if you just removed the state machine, you free the token and the next state machine is allocated with this exact token (not the smallest number, but the latest one). So it's hard to use.

So yes the feature is not fully designed yet.

erikjohnston commented 8 years ago

Okay, that's fair enough; I was just wondering if I had missed something. I know this is a work in progress, but I'm quite excited by the project and really want to try hacking some things together to get a feel for it. I'll just have to contain my impatience for now though :smile:

Keep up the good work!

tailhook commented 8 years ago

Okay, I've just pushed the "future" branch of "rotor" and "rotor-http". The basic idea is that you do:

let (port, future) = scope.pair()

The port is a thing used to push value to the future:

port.set(xxx)

This sets the value and wakes up the state machine that created the future initially. Port should be thread safe.

The future is received. It's expected to be looked at in .wakeup() handler:

if future.done() {
  value = future.get()
}

This is very preliminary API. Also, support of this in rotor-HTTP is mostly missing. But I'm publishing a branch just because people keep asking. To get things built, you may want to setup cargo config

Any feedback is appreciated.

erikjohnston commented 8 years ago

Wonderful, thanks for the update! I'll try and have a look over the next week, but the preliminary API looks good.

tailhook commented 8 years ago

Just released a version on crates.io. Hopefully add some docs soon.

erikjohnston commented 8 years ago

Fab! Thanks :)

On Mon, 4 Jan 2016 11:16 Paul Colomiets notifications@github.com wrote:

Just released a version on crates.io. Hopefully add some docs soon.

— Reply to this email directly or view it on GitHub https://github.com/tailhook/rotor/issues/3#issuecomment-168649540.