Module: Kernel

Defined in:
lib/concurrent/goroutine.rb

Class Method Summary collapse

Class Method Details

.go(*args, &block) ⇒ true, false

Note:

Althought based on Go’s goroutines and Erlang’s spawn/1,

Post the given agruments and block to the Global Thread Pool.

Ruby has a vastly different runtime. Threads aren’t nearly as efficient in Ruby. Use this function appropriately.

Parameters:

  • args (Array)

    zero or more arguments for the block

  • block (Proc)

    operation to be performed concurrently

Returns:

  • (true, false)

    success/failre of thread creation

See Also:



20
21
22
23
# File 'lib/concurrent/goroutine.rb', line 20

def go(*args, &block)
  return false unless block_given?
  $GLOBAL_THREAD_POOL.post(*args, &block)
end