Changeset 507

Show
Ignore:
Timestamp:
08/17/07 05:45:20 (1 year ago)
Author:
blackhedd
Message:

Added EventMachine#run_block

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/ChangeLog

    r506 r507  
    585815Aug07: Added parameters for EventMachine::Connection:start_tls that can be 
    5959        used to specify client-side private keys and certificates. 
     6017Aug07: Added EventMachine#run_block, a sugaring for a common use case. 
    6061 
  • version_0/lib/eventmachine.rb

    r502 r507  
    228228 
    229229 
     230    # Sugars a common use case. Will pass the given block to #run, but will terminate 
     231    # the reactor loop and exit the function as soon as the code in the block completes. 
     232    # (Normally, #run keeps running indefinitely, even after the block supplied to it 
     233    # finishes running, until user code calls #stop.) 
     234    # 
     235    def EventMachine::run_block &block 
     236            pr = proc { 
     237                    block.call 
     238                    EventMachine::stop 
     239            } 
     240            run &pr 
     241    end 
     242 
     243 
    230244  # +deprecated+ 
    231245  #-- 
  • version_0/tests/test_basic.rb

    r459 r507  
    9494  #-------------------------------------- 
    9595 
     96  # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS 
     97  # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor 
     98  # even after the supplied block completes. 
     99  def test_run_block 
     100          a = nil 
     101          EM.run_block { a = "Worked" } 
     102          assert a 
     103  end 
     104 
     105 
     106  #-------------------------------------- 
     107 
    96108end 
    97109