Skip to main content

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


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.3.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requeue-0.3.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file requeue-0.3.0.tar.gz.

File metadata

  • Download URL: requeue-0.3.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for requeue-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bae0124f54ddbc7858369a84d47df8d8717722f364a65ced8fbd74b56f383e0d
MD5 f4c3206fbb851ae8cc1ef7843a5e12ed
BLAKE2b-256 337ef5744b51892f00e026799d89dac2420255cbdd539eb90376d5024f3f66e6

See more details on using hashes here.

File details

Details for the file requeue-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: requeue-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for requeue-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eaa8030d47c4eb9000fe89b5df4797c8184ebf73f53e2e840644c88e78036a86
MD5 ba86b93e6dffae804d29010b6a677c56
BLAKE2b-256 66d7792e591f02f7429c218f61faef635764e6554d88db4b2fe257b7cddaa31e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page