a
    xdZ
                     @   sj   d dl mZ d dlZd dlmZ ddlmZ ddlmZ ddlmZ ejddd	G d
d dejdZdS )    )defaultdictN)asynccontextmanager   )_core)_util)EventF)eqhashc                   @   sP   e Zd ZdZejdd ddZejeddZejdddZ	e
eddd	Zd
S )	Sequencera  A convenience class for forcing code in different tasks to run in an
    explicit linear order.

    Instances of this class implement a ``__call__`` method which returns an
    async context manager. The idea is that you pass a sequence number to
    ``__call__`` to say where this block of code should go in the linear
    sequence. Block 0 starts immediately, and then block N doesn't start until
    block N-1 has finished.

    Example:
      An extremely elaborate way to print the numbers 0-5, in order::

         async def worker1(seq):
             async with seq(0):
                 print(0)
             async with seq(4):
                 print(4)

         async def worker2(seq):
             async with seq(2):
                 print(2)
             async with seq(5):
                 print(5)

         async def worker3(seq):
             async with seq(1):
                 print(1)
             async with seq(3):
                 print(3)

         async def main():
            seq = trio.testing.Sequencer()
            async with trio.open_nursery() as nursery:
                nursery.start_soon(worker1, seq)
                nursery.start_soon(worker2, seq)
                nursery.start_soon(worker3, seq)

    c                   C   s   t tS )N)r   r    r   r   O/var/www/html/Ranjet/env/lib/python3.9/site-packages/trio/testing/_sequencer.py<lambda>8       zSequencer.<lambda>F)factoryinit)defaultr   )positionc              	   C  s   || j v rtd|| jr&td| j | |dkrz| j|  I d H  W n: tjy   d| _| j	 D ]}|
  qrtdY n0 | jrtdzd V  W | j|d  
  n| j|d  
  0 d S )Nz%Attempted to re-use sequence point {}zsequence broken!r   Tz+Sequencer wait cancelled -- sequence broken   )_claimedRuntimeErrorformat_brokenadd_sequence_pointswaitr   Z	Cancelledvaluesset)selfr   eventr   r   r   __call__=   s$    

zSequencer.__call__N)__name__
__module____qualname____doc__attribr   r   r   r   r   intr   r   r   r   r   r
      s   'r
   )	metaclass)collectionsr   r$   async_generatorr    r   r   r   DefaultDictSetsFinalr
   r   r   r   r   <module>   s   