Class: Svent::EventCallbackFiber

Inherits:
Object
  • Object
show all
Defined in:
lib/svent/event_callback_fiber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper, name, callback, info) ⇒ EventCallbackFiber

Returns a new instance of EventCallbackFiber.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/svent/event_callback_fiber.rb', line 12

def initialize(helper, name, callback, info)
  @name = name
  @info = info
  @callback = callback
  @fiber = Fiber.new do
    @callback.call(helper, info)
    @fiber = nil
  end
  # self.resume
  @return = nil
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



10
11
12
# File 'lib/svent/event_callback_fiber.rb', line 10

def callback
  @callback
end

#infoObject (readonly)

Returns the value of attribute info.



9
10
11
# File 'lib/svent/event_callback_fiber.rb', line 9

def info
  @info
end

#nameObject (readonly)

Wrap the event callback function with Fiber.



8
9
10
# File 'lib/svent/event_callback_fiber.rb', line 8

def name
  @name
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/svent/event_callback_fiber.rb', line 32

def alive?
  @fiber != nil
end

#resumeObject



24
25
26
27
28
29
30
# File 'lib/svent/event_callback_fiber.rb', line 24

def resume
  if @return
    @fiber = nil
  else
    @return = @fiber.resume
  end
end