Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Queue #2

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "asyncgui-ext-synctools"
version = "0.2.0"
version = "0.2.1.dev0"
description = "Inter-task sychronization and communication."
authors = ["Nattōsai Mitō <[email protected]>"]
license = "MIT"
Expand Down
8 changes: 8 additions & 0 deletions sphinx/box.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
===
Box
===

.. automodule:: asyncgui_ext.synctools.box
:members:
:undoc-members:
:exclude-members:
8 changes: 8 additions & 0 deletions sphinx/event.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=====
Event
=====

.. automodule:: asyncgui_ext.synctools.event
:members:
:undoc-members:
:exclude-members:
4 changes: 3 additions & 1 deletion sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Inter-task sychronization and communication.
.. toctree::
:hidden:

reference
box
event
queue
8 changes: 8 additions & 0 deletions sphinx/queue.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=====
Queue
=====

.. automodule:: asyncgui_ext.synctools.queue
:members:
:undoc-members:
:exclude-members:
9 changes: 0 additions & 9 deletions sphinx/reference.rst

This file was deleted.

4 changes: 2 additions & 2 deletions src/asyncgui_ext/synctools/all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = (
'Event', 'Box',
'Event', 'Box', 'Queue',
)
from .event import Event
from .box import Box

from .queue import Queue
42 changes: 21 additions & 21 deletions src/asyncgui_ext/synctools/box.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
__all__ = ('Box', )
import types

'''
.. code-block::

class Box:
'''
Similar to :class:`asyncgui.AsyncBox`, but this one can handle multiple tasks simultaneously.
This is the closest thing to :class:`asyncio.Event` in this library.

.. code-block::
import asyncgui as ag
from asyncgui_ext.synctools.box import Box

async def async_fn(b1, b2):
args, kwargs = await b1.get()
async def async_fn1(box):
for __ in range(10):
args, kwargs = await box.get()
assert args == (1, )
assert kwargs == {'crow': 'raven', }

args, kwargs = await b2.get()
async def async_fn2(box):
for __ in range(10):
args, kwargs = await box.get()
assert args == (2, )
assert kwargs == {'frog': 'toad', }

args, kwargs = await b1.get()
assert args == (1, )
assert kwargs == {'crow': 'raven', }
box = Box()
box.put(1, crow='raven')
ag.start(async_fn1(box))
box.update(2, frog='toad')
ag.start(async_fn2(box))
'''


__all__ = ('Box', )
import types

b1 = Box()
b2 = Box()
b1.put(1, crow='raven')
start(async_fn(b1, b2))
b2.put(2, frog='toad')
'''

class Box:
__slots__ = ('_item', '_waiting_tasks', )

def __init__(self):
Expand Down
44 changes: 25 additions & 19 deletions src/asyncgui_ext/synctools/event.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
__all__ = ('Event', )
import types
'''
.. code-block::

import asyncgui as ag
from asyncgui_ext.synctools.event import Event

class Event:
'''
Similar to :class:`asyncgui.AsyncEvent`, but this one can handle multiple tasks simultaneously.
async def async_fn1(e):
args, kwargs = await e.wait()
assert args == (1, )
assert kwargs == {'crow': 'raven', }

.. code-block::
args, kwargs = await e.wait()
assert args == (2, )
assert kwargs == {'toad': 'frog', }

async def async_fn(e):
args, kwargs = await e.wait()
assert args == (2, )
assert kwargs == {'crow': 'raven', }
async def async_fn2(e):
args, kwargs = await e.wait()
assert args == (2, )
assert kwargs == {'toad': 'frog', }

args, kwargs = await e.wait()
assert args == (3, )
assert kwargs == {'toad': 'frog', }
e = Event()
ag.start(async_fn1(e))
e.fire(1, crow='raven')
ag.start(async_fn2(e))
e.fire(2, toad='frog')
'''

__all__ = ('Event', )
import types

e = Event()
e.fire(1, crocodile='alligator')
start(async_fn(e))
e.fire(2, crow='raven')
e.fire(3, toad='frog')
'''

class Event:
__slots__ = ('_waiting_tasks', )

def __init__(self):
Expand Down
Loading
Loading