Method: OpenWFE::Engine#wait_for
- Defined in:
- lib/openwfe/engine/engine.rb
#wait_for(fei_or_wfid) ⇒ Object
Waits for a given process instance to terminate. The method only exits when the flow terminates, but beware : if the process already terminated, the method will never exit.
The parameter can be a FlowExpressionId instance, for example the one given back by a launch(), or directly a workflow instance id (String).
This method is mainly used in utests.
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/openwfe/engine/engine.rb', line 482 def wait_for (fei_or_wfid) wfid = if fei_or_wfid.kind_of?(FlowExpressionId) fei_or_wfid.workflow_instance_id else fei_or_wfid end t = Thread.new { Thread.stop } to = get_expression_pool.add_observer(:terminate) do |c, fe, wi| t.wakeup if (fe.fei.workflow_instance_id == wfid and t.alive?) end te = get_expression_pool.add_observer(:error) do |c, fei, m, i, e| t.wakeup if (fei.parent_wfid == wfid and t.alive?) end #tc = get_expression_pool.add_observer(:cancel) do |c, fe| # if (fe.fei.wfid == wfid and fe.fei.expid == "0" and t.alive?) # sleep 0.500 # t.wakeup # end #end linfo { "wait_for() #{wfid}" } t.join get_expression_pool.remove_observer(to, :terminate) get_expression_pool.remove_observer(te, :error) #get_expression_pool.remove_observer(tc, :cancel) # # it would work as well without specifying the channel, # but it's thus a little bit faster end |