Async-Channel 2.2.1
Python multi-task communication library. Used by OctoBot project.
With python3 : pip install async-channel
Example
import async_channel.consumer as consumer
import async_channel.producer as producer
import async_channel.channels as channels
import async_channel.util as util
class AwesomeProducer(producer.Producer):
pass
class AwesomeConsumer(consumer.Consumer):
pass
class AwesomeChannel(channels.Channel):
PRODUCER_CLASS = AwesomeProducer
CONSUMER_CLASS = AwesomeConsumer
async def callback(data):
print("Consumer called !")
print("Received : " + data)
# Creates the channel
await util.create_channel_instance(AwesomeChannel, channels.Channels)
# Add a new consumer to the channel
await channels.Channels.get_chan("Awesome").new_consumer(callback)
# Creates a producer that send data to the consumer through the channel
producer = AwesomeProducer(channels.Channels.get_chan("Awesome"))
await producer.run()
await producer.send("test")
# Stops the channel with all its producers and consumers
# await channels.Channels.get_chan("Awesome").stop()