File: defer_spec.rb

package info (click to toggle)
ruby-em-synchrony 1.0.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 572 kB
  • sloc: ruby: 3,458; sh: 37; sql: 7; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 623 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "spec/helper/all"

describe EventMachine::Synchrony do

  it "defer: simple" do
    EM.synchrony do
      x = 1
    
      result = EM::Synchrony.defer do
        x = 2
        sleep 0.1
        3
      end
      
      result.should == 3      
      x.should == 2
      
      EM.stop    
    end
  end
  
  it "defer: with lambda" do
    EM.synchrony do
    
      x = 1
      
      op = lambda do
        sleep 0.1
        x += 1
        3
      end
      
      EM::S.defer(op).should == 3
      x.should == 2
              
      EM.stop
    end                                                  
  end
  
end