Skip to content

mapogolions/pyreact-event-loop

Repository files navigation

Pyreact event loop

Build Status Coverage Status GitHub license

It's modest attempt to implement the reactor pattern to break the traditional synchronous flow. The event loop uses a single thread and is responsible for scheduling asynchronous operations.

Introduction

In JS event loop is available out of the box. It is working behind the scenes. Asynchronous code in JS looks like this:

setTimeout(() => console.log('world!'), 1000);
console.log("Hello ");

the same things with pyreact-event-loop:

loop = event_loop.SelectLoop()
loop.add_timer(1, lambda: print("world!"))
loop.future_tick(lambda: print("Hello "))
loop.run()

In python needs to explicitly define the event loop.

By standing on the shoulders of Giants

Pyreact-event-loop based on ReactPHP event loop component.

There are three available implementations:

  • SelectLoop uses the select module
  • LibevLoop uses the mood.event python libev interface
  • LibuvLoop uses the pyuv python interface for libuv

Examples

How to use

docker build github.com/mapogolions/pyreact-event-loop -t mapogolions/eventloop
docker run -it mapogolions/eventloop # ./timers.py
# or you could pass a relative file path
docker run -it mapogolions/eventloop ./periodic.py
docker run -it mapogolions/eventloop ./fp-streams.py

For deployment see .travis.yml

About

Reactor pattern

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published