jfhbrook / pyee

A rough port of Node.js's EventEmitter to Python with a few tricks of its own
https://github.com/jfhbrook/public
MIT License
371 stars 39 forks source link

Using in Multiple Scripts #92

Closed drixie closed 2 years ago

drixie commented 2 years ago

How do I use this event emitter in multiple scripts?

In NodeJS, I can export the event in one script, and subscribe to a channel in another script after importing the same channel.

How do I so the same with Pyee in Python? Any code suggestions will be appreciated.

jfhbrook commented 2 years ago

You should be able to do that here:

# my_events.py
from pyee.base import EventEmitter

ee = new EventEmitter

# a.py
from my_events import ee

ee.emit('lol', {})

# b.py
from my_events import ee

ee.on('lol', print)

# __init__.py
import a
import b

Similar kind of mutability that you get with module.exports and require.

Going to close this since there's no real action to take on my part. Cheers!