blinds icon indicating copy to clipboard operation
blinds copied to clipboard

Add an example that demonstrates running multiple futures

Open ryanisaacg opened this issue 4 years ago • 5 comments

ryanisaacg avatar Jan 15 '20 18:01 ryanisaacg

I think there are still some examples in #12 (specifically, a task which is like a stream that creates many events, and a task which is started in response to a window action) that aren't covered in this PR, but I think this PR demonstrates some techniques that I'll try to use to still get what I want without requiring "breaking into" the blinds-owned event loop.

johnpmayer avatar Jan 15 '20 23:01 johnpmayer

Mostly stream of consciousness:

The app can initialize a futures_util::stream::FuturesUnordered, and the main loop can select on either Stream.poll_next() or EventStream.next_event(). In the case of responding to a "service event", the loop should just handle that (like interpret the net response), while when handling a window event, the loop should handle the whole batch of window events, and do a draw iteration.

Actually, something that isn't quite clear is whether there's an appropriate way to put things on the animation frame. That's a concept that sort of got lost between 0.3 and 0.4 (unless I missed it).

johnpmayer avatar Jan 16 '20 00:01 johnpmayer

Yeah, I'm stuck. How would you implement something like tick_loop without having access to the executor? I just discovered that you can't start one LocalPool inside another.

johnpmayer avatar Jan 16 '20 03:01 johnpmayer

With tick_loop, I would probably just use the instant crate to support Instant on web and desktop, and write a small polling timer.

ryanisaacg avatar Jan 16 '20 05:01 ryanisaacg

Sorry, I didn't mean other cross-platform libraries. I'm new to async in Rust and am trying to reconcile all the combinators against more direct control over the event loop. The thing I'm having trouble expressing is adding new futures to the set of things I'm polling for each loop, including tasks that produce a stream. The examples here only deal with "startup tasks". In #12 I showed examples like this.

My ultimate motivation of course is networking - websockets and RPC are examples of long-lived or in-response-to kinds of async actions.

edit: I have something reasonable now, based on FuturesUnordered, which I will share

johnpmayer avatar Jan 16 '20 13:01 johnpmayer