Class: Fiber

Inherits:
Object show all
Defined in:
lib/joffice/fiber_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete_subscription(node) ⇒ Object



56
57
58
# File 'lib/joffice/fiber_extensions.rb', line 56

def delete_subscription(node)
  subscriptions.delete(node)      
end

.delete_subscriptionsObject



60
61
62
# File 'lib/joffice/fiber_extensions.rb', line 60

def delete_subscriptions
  current.subscriptions.clear    
end

.set_subscription(node, value) ⇒ Object



64
65
66
# File 'lib/joffice/fiber_extensions.rb', line 64

def set_subscription(node, value)
  subscriptions[node]=value      
end

.sleep(timeout) ⇒ Object



38
39
40
41
42
# File 'lib/joffice/fiber_extensions.rb', line 38

def sleep(timeout)
  f=current
  EventMachine::Timer.new(timeout) { f.resume }
  Fiber.yield
end

.sleep_to_next_tickObject



33
34
35
36
# File 'lib/joffice/fiber_extensions.rb', line 33

def sleep_to_next_tick
  current.run_on_next_tick(nil)
  Fiber.yield
end

.subscribed?(node) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/joffice/fiber_extensions.rb', line 52

def subscribed?(node)
  subscriptions.has_key?(node)      
end

.subscription(node) ⇒ Object



48
49
50
# File 'lib/joffice/fiber_extensions.rb', line 48

def subscription(node)
  subscriptions[node]      
end

.subscriptionsObject



44
45
46
# File 'lib/joffice/fiber_extensions.rb', line 44

def subscriptions
  current.subscriptions     
end

Instance Method Details

#run_on_next_tick(value) ⇒ Object



22
23
24
25
26
# File 'lib/joffice/fiber_extensions.rb', line 22

def run_on_next_tick(value)
  EM.next_tick do
    resume(value) if alive?
  end
end

#subscriptionsObject



28
29
30
# File 'lib/joffice/fiber_extensions.rb', line 28

def subscriptions
  @subscriptions||={}      
end