Class: Foolio::Loop

Inherits:
Object
  • Object
show all
Includes:
Listener
Defined in:
lib/foolio/loop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Listener

#callback

Constructor Details

#initialize(loop) ⇒ Loop

Returns a new instance of Loop.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/foolio/loop.rb', line 17

def initialize(loop)
  @loop = loop

  timer.start(1) do
    if @stop
      Foolio::UV.close_all(@loop, callback{
                             clear_callbacks
                           })
    end
  end
end

Instance Attribute Details

#loopObject (readonly)

Returns the value of attribute loop.



6
7
8
# File 'lib/foolio/loop.rb', line 6

def loop
  @loop
end

Class Method Details

.createObject



12
13
14
# File 'lib/foolio/loop.rb', line 12

def create
  self.new Foolio::UV.loop_new
end

.defaultObject



8
9
10
# File 'lib/foolio/loop.rb', line 8

def default
  self.new Foolio::UV.default_loop
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/foolio/loop.rb', line 66

def alive?
  not @stop
end

#file_stat(path, &block) ⇒ Object



55
56
57
58
59
60
# File 'lib/foolio/loop.rb', line 55

def file_stat(path, &block)
  cb = callback{|event, _|
    block[path, event]
  }
  Foolio::UV.fs_event_init(@loop, path, cb, 0)
end

#force_stopObject



74
75
76
77
# File 'lib/foolio/loop.rb', line 74

def force_stop
  @stop = true
  Foolio::UV.loop_delete @loop
end

#idleObject



29
30
31
# File 'lib/foolio/loop.rb', line 29

def idle
  Foolio::Idle.new(self, Foolio::UV.idle_init(@loop))
end

#runObject



62
63
64
# File 'lib/foolio/loop.rb', line 62

def run
  Foolio::UV.run @loop
end

#stopObject



70
71
72
# File 'lib/foolio/loop.rb', line 70

def stop
  @stop = true
end

#tcp(ip, port) ⇒ Object



37
38
39
40
41
42
# File 'lib/foolio/loop.rb', line 37

def tcp(ip, port)
  handle = Foolio::UV.tcp_init(@loop)
  @socket = Foolio::UV.ip4_addr(ip, port)
  Foolio::UV.tcp_bind(handle, @socket)
  Foolio::TCP.new self, handle
end

#timerObject



33
34
35
# File 'lib/foolio/loop.rb', line 33

def timer
  Foolio::Timer.new(self, Foolio::UV.timer_init(@loop))
end

#udpObject



44
45
46
47
# File 'lib/foolio/loop.rb', line 44

def udp
  handle = Foolio::UV.udp_init(@loop)
  Foolio::UDP.new self, handle
end

#unix(path, ipc = 0) ⇒ Object



49
50
51
52
53
# File 'lib/foolio/loop.rb', line 49

def unix(path, ipc = 0)
  handle = Foolio::UV.pipe_init(@loop, ipc)
  Foolio::UV.pipe_bind(handle, path)
  Foolio::Pipe.new self, handle
end