You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

aioqueueext

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aioqueueext

Asyncio queues with extended functionality: peeking, setting put and get callbacks.

0.2.1
pipPyPI
Maintainers
1

aioqueueext

A package that provides asyncio Queues with additional functionality.

Work-in-Progress

The repository contains modules extracted from my other project and was refactored as a separate package.

In the current version, I have not verified all of the functions.

Additional functions I plan to implement are:

  • return_when_*() - async functions to ease synchronization tasks
  • set_on_get_callback()
  • set_on_put_callback()
  • peek_nowait() - returns the "up-next" item without removing it from the queue
  • peek_and_get() - async peek and conditionally get (pop) an item from the queue

Examples

Sync Peeking

async def sync_peeking_example() -> None:
    queue1 = QueueExt()

    await queue1.put("apple")

    item = queue1.peek_nowait()
    print(f"first peek: {item}")  # "apple"

    await queue1.put("banana")

    item = queue1.peek_nowait()
    print(f"second peek: {item}")  # "apple"

    item = await queue1.get()  # popped "apple"

    item = queue1.peek_nowait()
    print(f"third peek: {item}")  # "banana"

    item = await queue1.get()  # popped "banana"

    # the next peek raises the QueueEmpty exception
    try:
        print(f"fourth peek: {queue1.peek_nowait()}")
    except asyncio.QueueEmpty:
        print("fourth peek failed: QueueEmpty")

Keywords

asyncio

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts