An asynchronous queue for requesting data
Project description
Requeue
In applications that receive messages, like chat bots, where you run callbacks on incoming messages, you might want to capture follow-up messages within a callback. A request queue allows you to do that.
Examples
from requeue import Requeue
queue = Requeue()
Where the messages come in and are processed;
async def run_callbacks(message):
# If the message completes a request, since it is forwarded,
# it should not continue to be handled by the callbacks.
if await queue.complete(message):
return
# If no request was completed, the message can be processed as usual.
for callback in client.callbacks:
await callback(message)
Inside a callback, to request and await an incoming message, you use wait_for
.
To only accept a message that meets specific criteria, you can pass a function
as a filter to the check
parameter.
@client.callback
async def on_message(message):
# An example of a knock knock joke back-and-forth,
# using the request queue to pick out the responses
if message == 'Knock knock!':
await client.send("Who's there?")
who = await queue.wait_for()
await client.send(f'{who} who?')
punchline = await queue.wait_for()
await punchline.react('😂')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
requeue-0.2.0.post1.tar.gz
(14.5 kB
view hashes)
Built Distribution
Close
Hashes for requeue-0.2.0.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b790200911278bdab572fb69e686b05f792884d0b55d086dd894524cf6aa90dd |
|
MD5 | e95e8e303dba366a179d5bd39b484158 |
|
BLAKE2b-256 | 1c02a3f171ed617c97c5753ea696ba085698d0178b703e5880a35715867c129a |