<s> from diesel import fork , fire , wait , sleep , first <EOL> from diesel . util . event import Event <EOL> def test_basic_fire ( ) : <EOL> done = Event ( ) <EOL> v = [ <NUM_LIT:0> ] <EOL> def w ( ) : <EOL> while True : <EOL> wait ( "<STR_LIT>" ) <EOL> v [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> def f ( ) : <EOL> sleep ( <NUM_LIT> ) <EOL> fire ( "<STR_LIT>" ) <EOL> sleep ( <NUM_LIT> ) <EOL> fire ( "<STR_LIT>" ) <EOL> done . set ( ) <EOL> fork ( f ) <EOL> fork ( w ) <EOL> ev , _ = first ( sleep = <NUM_LIT:1> , waits = [ done ] ) <EOL> assert v [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> def test_fire_multiple ( ) : <EOL> done = Event ( ) <EOL> v = [ <NUM_LIT:0> ] <EOL> def w ( ) : <EOL> while True : <EOL> wait ( "<STR_LIT>" ) <EOL> v [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> def f ( ) : <EOL> sleep ( <NUM_LIT> ) <EOL> fire ( "<STR_LIT>" ) <EOL> sleep ( <NUM_LIT> ) <EOL> fire ( "<STR_LIT>" ) <EOL> done . set ( ) <EOL> fork ( f ) <EOL> fork ( w ) <EOL> fork ( w ) <EOL> ev , _ = first ( sleep = <NUM_LIT:1> , waits = [ done ] ) <EOL> assert v [ <NUM_LIT:0> ] == <NUM_LIT:4> <EOL> def test_fire_miss ( ) : <EOL> done = Event ( ) <EOL> v = [ <NUM_LIT:0> ] <EOL> def w ( ) : <EOL> while True : <EOL> wait ( "<STR_LIT>" ) <EOL> v [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> def f ( ) : <EOL> sleep ( <NUM_LIT> ) <EOL> fire ( "<STR_LIT>" ) <EOL> done . set ( ) <EOL> fork ( f ) <EOL> fork ( w ) <EOL> fork ( w ) <EOL> ev , _ = first ( sleep = <NUM_LIT:1> , waits = [ done ] ) <EOL> assert v [ <NUM_LIT:0> ] == <NUM_LIT:0> </s>
