src/Pure/System/event_bus.scala
changeset 38849 2f198d107aef
parent 38428 c13c95c97e89
child 43406 40c67d894be4
equal deleted inserted replaced
38848:9483bb678d96 38849:2f198d107aef
    30 
    30 
    31 
    31 
    32   /* event invocation */
    32   /* event invocation */
    33 
    33 
    34   def event(x: Event) { synchronized { receivers.foreach(_ ! x) } }
    34   def event(x: Event) { synchronized { receivers.foreach(_ ! x) } }
       
    35 
       
    36 
       
    37   /* await global condition -- triggered via bus events */
       
    38 
       
    39   def await(cond: => Boolean)
       
    40   {
       
    41     case object Wait
       
    42     val a = new Actor {
       
    43       def act {
       
    44         if (cond) react { case Wait => reply(()); exit(Wait) }
       
    45         else {
       
    46           loop {
       
    47             react {
       
    48               case trigger if trigger != Wait =>
       
    49                 if (cond) { react { case Wait => reply(()); exit(Wait) } }
       
    50             }
       
    51           }
       
    52         }
       
    53       }
       
    54     }
       
    55     this += a
       
    56     a.start
       
    57     a !? Wait
       
    58     this -= a
       
    59   }
    35 }
    60 }