
    vKg
                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKrSSK	J
r
JrJr  \(       a  S SKJr  \R                  \R                   " S	S	S
9 " S S5      5       5       rg)    )annotations)defaultdict)asynccontextmanager)TYPE_CHECKINGN   )Event_core_util)AsyncIteratorF)eqslotsc                      \ rS rSr% Sr\R                  " S SS9rS\S'   \R                  " \	SS9r
S\S	'   \R                  " SSS
9rS\S'   \SS j5       rSrg)	Sequencer   a`  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                      [        [        5      $ )N)r   r        W/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/trio/testing/_sequencer.py<lambda>Sequencer.<lambda>:   s	    E*r   F)factoryinitzdefaultdict[int, Event]_sequence_pointszset[int]_claimed)defaultr   bool_brokenc                 #    XR                   ;   a  [        SU 35      eU R                  (       a  [        S5      eU R                   R                  U5        US:w  aC   U R                  U   R                  5       I S h  vN   U R                  (       a  [        S5      e  S 7v   U R                  US-      R                  5         g  NH! [        R                   aE    SU l        U R                  R                  5        H  nUR                  5         M     [        S5      S ef = f! U R                  US-      R                  5         f = f7f)Nz"Attempted to reuse sequence point zsequence broken!r   Tz+Sequencer wait cancelled -- sequence broken   )
r   RuntimeErrorr   addr   waitr	   	Cancelledvaluesset)selfpositionevents      r   __call__Sequencer.__call__@   s    }}$!CH:NOO<<122(#q=;++H5::<<< <<&'9::  	6!!(Q,/335 =?? #!2299;EIIK <"A	 !!(Q,/335sI   AE
 C	 >C?C	 E
!D% &!E
C	 	AD""E
%"EE
)r   N)r'   intreturnzAsyncIterator[None])__name__
__module____qualname____firstlineno____doc__attrsfieldr   __annotations__r%   r   r   r   r)   __static_attributes__r   r   r   r   r      se    %N 16*1-  Su=Hh=KKE:GT:6 6r   r   )
__future__r   collectionsr   
contextlibr   typingr   r2    r   r	   r
   collections.abcr   finaldefiner   r   r   r   <module>r>      sS    " # *    " "- e$F6 F6 % F6r   