Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.68 KB

README.md

File metadata and controls

46 lines (35 loc) · 1.68 KB

OctoBot-Channels 1.3.11

PyPI Build Status Build status Coverage Status

OctoBot channels package.

Installation

With python3 : pip install OctoBot-Channels

Usage

Example

from octobot_channels import Consumer, Producer
from octobot_channels.channels import Channels, Channel
from octobot_channels.util import create_channel_instance

class AwesomeProducer(Producer):
    pass

class AwesomeConsumer(Consumer):
    pass

class AwesomeChannel(Channel):
    PRODUCER_CLASS = MyAwesomeProducer
    CONSUMER_CLASS = MyAwesomeConsumer

async def callback(data):
    print("Consumer called !")
    print("Received : " + data)

# Creates the channel
await create_channel_instance(MyChannel, Channels)

# Add a new consumer to the channel
await Channels.get_chan("Awesome").new_consumer(callback)

# Creates a producer that send data to the consumer through the channel
producer = TestProducer(Channels.get_chan("Awesome"))
await producer.run()
await producer.send("test")

# Stops the channel with all its producers and consumers
# await Channels.get_chan("Awesome").stop()