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

Support event loops #168

Open
thomasballinger opened this issue Nov 9, 2021 · 0 comments
Open

Support event loops #168

thomasballinger opened this issue Nov 9, 2021 · 0 comments

Comments

@thomasballinger
Copy link
Member

thomasballinger commented Nov 9, 2021

The Input class is like a reactor:

You can schedule events for the future (timers)

curtsies/curtsies/input.py

Lines 330 to 341 in 307aa87

def scheduled_event_trigger(
self, event_type: Type[events.ScheduledEvent]
) -> Callable[[float], None]:
"""Returns a callback that schedules events for the future.
Returned callback function will add an event of type event_type
to a queue which will be checked the next time an event is requested."""
def callback(when: float) -> None:
self.queued_scheduled_events.append((when, event_type(when=when)))
return callback

It uses select()

curtsies/curtsies/input.py

Lines 173 to 180 in 307aa87

(rs, _, _) = select.select(
[self.in_stream.fileno()]
+ ([] if self.wakeup_read_fd is None else [self.wakeup_read_fd])
+ self.readers,
[],
[],
remaining_timeout,
)

But it's still a "you call it," not an "it calls you" interface: you're supposed to iterate over it, but you can do as much work as you want before you call next(input) again.

To integrate event loops, these timers will need to be delegated to the real event loop as will checking whether stdin is ready.

Specifically, Twisted's reactors, specifically specifically cfreactor and gireactor.

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

1 participant