Module: NodeRb

Defined in:
lib/noderb.rb,
lib/noderb/fs.rb,
lib/noderb/dns.rb,
lib/noderb/tcp.rb,
lib/noderb/file.rb,
lib/noderb/defer.rb,
lib/noderb/tools.rb,
lib/noderb/timers.rb,
lib/noderb/process.rb,
lib/noderb/version.rb,
lib/noderb/next_tick.rb,
lib/noderb/connection.rb,
ext/noderb_extension/noderb.c

Defined Under Namespace

Modules: Connection, File, Modules, Process, Timer Classes: BackWorker, FileSystem, NativePointer, Stat

Constant Summary collapse

VERSION =
"0.0.12"

Class Method Summary collapse

Class Method Details

.defer(work = nil, callback = nil, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/noderb/defer.rb', line 15

def defer work = nil, callback = nil, &block
  work = block if not work and block
  callback = block if not callback and block
  work ||= proc { }
  callback ||= proc { |result| }
  NodeRb.defer_native(BackWorker.new(work), callback)
end

.killObject



3
4
5
6
7
8
# File 'lib/noderb/tools.rb', line 3

def self.kill
  NodeRb.next_tick do
    puts "Exiting"
    Kernel.exit(0)
  end
end

.next_tick(params = nil, &block) ⇒ Object



5
6
7
# File 'lib/noderb/next_tick.rb', line 5

def next_tick params = nil, &block
  next_tick_schedule(block, params)
end

.next_tick_executeObject



15
16
17
18
19
20
21
# File 'lib/noderb/next_tick.rb', line 15

def next_tick_execute
  blocks, @next_tick = @next_tick, []
  blocks.each do |block|
    block, params = block
    params ? block.call(params) : block.call
  end
end

.next_tick_nativeObject

Define utility methods

.next_tick_schedule(block, params) ⇒ Object



9
10
11
12
13
# File 'lib/noderb/next_tick.rb', line 9

def next_tick_schedule block, params
  @next_tick ||= []
  @next_tick << [block, params]
  NodeRb.send(:next_tick_native)
end

.once(timeout, &block) ⇒ Object



5
6
7
# File 'lib/noderb/timers.rb', line 5

def once timeout, &block
  NodeRb.once_native(timeout * 1000, 0, block)
end

.once_nativeObject

Timer related functions

.register_instanceObject

.repeat(repeat, handler, timeout = nil) ⇒ Object



9
10
11
12
# File 'lib/noderb/timers.rb', line 9

def repeat repeat, handler, timeout = nil
  timeout ||= repeat
  NodeRb.once_native(timeout * 1000, repeat * 1000, handler)
end

.resolve(hostname, &block) ⇒ Object



5
6
7
# File 'lib/noderb/dns.rb', line 5

def resolve hostname, &block
  NodeRb.resolve_native(hostname, block)
end

.resolve_nativeObject

DNS related methods

.startObject

Define starting methods

.start_client(address, port, clazz) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/noderb/tcp.rb', line 15

def start_client address, port, clazz
  if /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(address)
    NodeRb.start_client_native(address, port, clazz)
  else
    NodeRb.resolve(address) do |ip|
      NodeRb.start_client_native(ip, port, clazz)
    end
  end
end

.start_client_nativeObject

.start_processObject

.start_proxyObject

.start_server(address, port, clazz) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/noderb/tcp.rb', line 5

def start_server address, port, clazz
  if /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(address)
    NodeRb.start_server_native(address, port, clazz)
  else
    NodeRb.resolve(address) do |ip|
      NodeRb.start_server_native(ip, port, clazz)
    end
  end
end

.start_server_nativeObject

.stop_proxyObject

.unregister_instanceObject