tmm1-em-spec 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/em/spec.rb +46 -26
 - metadata +5 -4
 - data/lib/ext/em.rb +0 -37
 
    
        data/lib/em/spec.rb
    CHANGED
    
    | 
         @@ -2,18 +2,23 @@ require File.dirname(__FILE__) + '/../ext/fiber18' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'bacon'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            class Bacon::Context
         
     | 
| 
       6 
     | 
    
         
            -
              alias :_it :it
         
     | 
| 
      
 5 
     | 
    
         
            +
            class Bacon::FiberedContext < Bacon::Context
         
     | 
| 
       7 
6 
     | 
    
         
             
              def it *args
         
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
      
 7 
     | 
    
         
            +
                super{
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if block_given?
         
     | 
| 
      
 9 
     | 
    
         
            +
                    yield
         
     | 
| 
      
 10 
     | 
    
         
            +
                    Fiber.yield
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                }
         
     | 
| 
       9 
13 
     | 
    
         
             
              end
         
     | 
| 
       10 
14 
     | 
    
         | 
| 
       11 
15 
     | 
    
         
             
              def done
         
     | 
| 
       12 
16 
     | 
    
         
             
                EM.next_tick{
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :done.should == :done
         
     | 
| 
       13 
18 
     | 
    
         
             
                  $bacon_fiber.resume if $bacon_fiber
         
     | 
| 
       14 
19 
     | 
    
         
             
                }
         
     | 
| 
       15 
20 
     | 
    
         
             
              end
         
     | 
| 
       16 
     | 
    
         
            -
            end 
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
       17 
22 
     | 
    
         | 
| 
       18 
23 
     | 
    
         
             
            require 'eventmachine'
         
     | 
| 
       19 
24 
     | 
    
         | 
| 
         @@ -25,7 +30,7 @@ module EventMachine 
     | 
|
| 
       25 
30 
     | 
    
         
             
                EM.run{
         
     | 
| 
       26 
31 
     | 
    
         
             
                  Bacon.summary_on_exit
         
     | 
| 
       27 
32 
     | 
    
         
             
                  ($bacon_fiber = Fiber.new{
         
     | 
| 
       28 
     | 
    
         
            -
                                    Bacon:: 
     | 
| 
      
 33 
     | 
    
         
            +
                                    Bacon::FiberedContext.new(args.join(' '), &blk).run
         
     | 
| 
       29 
34 
     | 
    
         
             
                                    EM.stop_event_loop
         
     | 
| 
       30 
35 
     | 
    
         
             
                                  }).resume
         
     | 
| 
       31 
36 
     | 
    
         
             
                }
         
     | 
| 
         @@ -33,33 +38,48 @@ module EventMachine 
     | 
|
| 
       33 
38 
     | 
    
         
             
              class << self; alias :describe :spec; end
         
     | 
| 
       34 
39 
     | 
    
         
             
            end
         
     | 
| 
       35 
40 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
            if __FILE__ == $0
         
     | 
| 
       37 
42 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 43 
     | 
    
         
            +
              describe 'Bacon' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                should 'work as normal outside EM.describe' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                  1.should == 1
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
       41 
47 
     | 
    
         
             
              end
         
     | 
| 
       42 
48 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
               
     | 
| 
       44 
     | 
    
         
            -
                 
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                EM.add_timer(0.5){
         
     | 
| 
       47 
     | 
    
         
            -
                  (Time.now-start).should.be.close 0.5, 0.1
         
     | 
| 
      
 49 
     | 
    
         
            +
              EM.describe EventMachine do
         
     | 
| 
      
 50 
     | 
    
         
            +
                should 'work' do
         
     | 
| 
       48 
51 
     | 
    
         
             
                  done
         
     | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
       51 
53 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                start = Time.now
         
     | 
| 
      
 54 
     | 
    
         
            +
                should 'have timers' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  start = Time.now
         
     | 
| 
       55 
56 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                    (Time.now-start).should.be.close 1.0, 0.1
         
     | 
| 
       59 
     | 
    
         
            -
                    EM.__send__ :cancel_timer, timer
         
     | 
| 
      
 57 
     | 
    
         
            +
                  EM.add_timer(0.5){
         
     | 
| 
      
 58 
     | 
    
         
            +
                    (Time.now-start).should.be.close 0.5, 0.1
         
     | 
| 
       60 
59 
     | 
    
         
             
                    done
         
     | 
| 
       61 
     | 
    
         
            -
                   
     | 
| 
       62 
     | 
    
         
            -
                 
     | 
| 
      
 60 
     | 
    
         
            +
                  }
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                should 'have periodic timers' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  num = 0
         
     | 
| 
      
 65 
     | 
    
         
            +
                  start = Time.now
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  timer = EM.add_periodic_timer(0.5){
         
     | 
| 
      
 68 
     | 
    
         
            +
                    if (num += 1) == 2
         
     | 
| 
      
 69 
     | 
    
         
            +
                      (Time.now-start).should.be.close 1.0, 0.1
         
     | 
| 
      
 70 
     | 
    
         
            +
                      EM.__send__ :cancel_timer, timer
         
     | 
| 
      
 71 
     | 
    
         
            +
                      done
         
     | 
| 
      
 72 
     | 
    
         
            +
                    end
         
     | 
| 
      
 73 
     | 
    
         
            +
                  }
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                should 'have deferrables' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  defr = EM::DefaultDeferrable.new
         
     | 
| 
      
 78 
     | 
    
         
            +
                  defr.timeout(1)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  defr.errback{
         
     | 
| 
      
 80 
     | 
    
         
            +
                    done
         
     | 
| 
      
 81 
     | 
    
         
            +
                  }
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
       63 
83 
     | 
    
         
             
              end
         
     | 
| 
       64 
84 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
            end 
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: tmm1-em-spec
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Aman Gupta
         
     | 
| 
         @@ -9,20 +9,22 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-02-15 00:00:00 -08:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: eventmachine
         
     | 
| 
      
 17 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
       17 
18 
     | 
    
         
             
              version_requirement: 
         
     | 
| 
       18 
19 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
       19 
20 
     | 
    
         
             
                requirements: 
         
     | 
| 
       20 
21 
     | 
    
         
             
                - - ">="
         
     | 
| 
       21 
22 
     | 
    
         
             
                  - !ruby/object:Gem::Version 
         
     | 
| 
       22 
     | 
    
         
            -
                    version: 0.12. 
     | 
| 
      
 23 
     | 
    
         
            +
                    version: 0.12.4
         
     | 
| 
       23 
24 
     | 
    
         
             
                version: 
         
     | 
| 
       24 
25 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       25 
26 
     | 
    
         
             
              name: bacon
         
     | 
| 
      
 27 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
       26 
28 
     | 
    
         
             
              version_requirement: 
         
     | 
| 
       27 
29 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
       28 
30 
     | 
    
         
             
                requirements: 
         
     | 
| 
         @@ -41,7 +43,6 @@ extra_rdoc_files: [] 
     | 
|
| 
       41 
43 
     | 
    
         
             
            files: 
         
     | 
| 
       42 
44 
     | 
    
         
             
            - README
         
     | 
| 
       43 
45 
     | 
    
         
             
            - lib/em/spec.rb
         
     | 
| 
       44 
     | 
    
         
            -
            - lib/ext/em.rb
         
     | 
| 
       45 
46 
     | 
    
         
             
            - lib/ext/fiber18.rb
         
     | 
| 
       46 
47 
     | 
    
         
             
            has_rdoc: false
         
     | 
| 
       47 
48 
     | 
    
         
             
            homepage: http://github.com/tmm1/em-spec
         
     | 
    
        data/lib/ext/em.rb
    DELETED
    
    | 
         @@ -1,37 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            begin
         
     | 
| 
       2 
     | 
    
         
            -
              require 'eventmachine'
         
     | 
| 
       3 
     | 
    
         
            -
            rescue LoadError
         
     | 
| 
       4 
     | 
    
         
            -
              require 'rubygems'
         
     | 
| 
       5 
     | 
    
         
            -
              require 'eventmachine'
         
     | 
| 
       6 
     | 
    
         
            -
            end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            # copied from EM trunk, will be removed when 0.12.1 is released
         
     | 
| 
       9 
     | 
    
         
            -
            if EM::VERSION < '0.12.1'
         
     | 
| 
       10 
     | 
    
         
            -
                
         
     | 
| 
       11 
     | 
    
         
            -
              def EventMachine::run blk=nil, tail=nil, &block
         
     | 
| 
       12 
     | 
    
         
            -
                @tails ||= []
         
     | 
| 
       13 
     | 
    
         
            -
                tail and @tails.unshift(tail)
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                if reactor_running?
         
     | 
| 
       16 
     | 
    
         
            -
                  (b = blk || block) and b.call # next_tick(b)
         
     | 
| 
       17 
     | 
    
         
            -
                else
         
     | 
| 
       18 
     | 
    
         
            -
                  @conns = {}
         
     | 
| 
       19 
     | 
    
         
            -
                  @acceptors = {}
         
     | 
| 
       20 
     | 
    
         
            -
                  @timers = {}
         
     | 
| 
       21 
     | 
    
         
            -
                  begin
         
     | 
| 
       22 
     | 
    
         
            -
                    @reactor_running = true
         
     | 
| 
       23 
     | 
    
         
            -
                    initialize_event_machine
         
     | 
| 
       24 
     | 
    
         
            -
                    (b = blk || block) and add_timer(0, b)
         
     | 
| 
       25 
     | 
    
         
            -
                    run_machine
         
     | 
| 
       26 
     | 
    
         
            -
                  ensure
         
     | 
| 
       27 
     | 
    
         
            -
                    release_machine
         
     | 
| 
       28 
     | 
    
         
            -
                    @reactor_running = false
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  until @tails.empty?
         
     | 
| 
       32 
     | 
    
         
            -
                    @tails.pop.call
         
     | 
| 
       33 
     | 
    
         
            -
                  end
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
            end
         
     |