|
1 | | -__all__ = ('Box', ) |
2 | | -import types |
3 | | - |
| 1 | +''' |
| 2 | +.. code-block:: |
4 | 3 |
|
5 | | -class Box: |
6 | | - ''' |
7 | | - Similar to :class:`asyncgui.AsyncBox`, but this one can handle multiple tasks simultaneously. |
8 | | - This is the closest thing to :class:`asyncio.Event` in this library. |
9 | | -
|
10 | | - .. code-block:: |
| 4 | + import asyncgui as ag |
| 5 | + from asyncgui_ext.synctools.box import Box |
11 | 6 |
|
12 | | - async def async_fn(b1, b2): |
13 | | - args, kwargs = await b1.get() |
| 7 | + async def async_fn1(box): |
| 8 | + for __ in range(10): |
| 9 | + args, kwargs = await box.get() |
14 | 10 | assert args == (1, ) |
15 | 11 | assert kwargs == {'crow': 'raven', } |
16 | 12 |
|
17 | | - args, kwargs = await b2.get() |
| 13 | + async def async_fn2(box): |
| 14 | + for __ in range(10): |
| 15 | + args, kwargs = await box.get() |
18 | 16 | assert args == (2, ) |
19 | 17 | assert kwargs == {'frog': 'toad', } |
20 | 18 |
|
21 | | - args, kwargs = await b1.get() |
22 | | - assert args == (1, ) |
23 | | - assert kwargs == {'crow': 'raven', } |
| 19 | + box = Box() |
| 20 | + box.put(1, crow='raven') |
| 21 | + ag.start(async_fn1(box)) |
| 22 | + box.update(2, frog='toad') |
| 23 | + ag.start(async_fn2(box)) |
| 24 | +''' |
| 25 | + |
| 26 | + |
| 27 | +__all__ = ('Box', ) |
| 28 | +import types |
24 | 29 |
|
25 | | - b1 = Box() |
26 | | - b2 = Box() |
27 | | - b1.put(1, crow='raven') |
28 | | - start(async_fn(b1, b2)) |
29 | | - b2.put(2, frog='toad') |
30 | | - ''' |
31 | 30 |
|
| 31 | +class Box: |
32 | 32 | __slots__ = ('_item', '_waiting_tasks', ) |
33 | 33 |
|
34 | 34 | def __init__(self): |
|
0 commit comments