Module: Aw

Defined in:
lib/aw.rb,
lib/aw/fork.rb

Overview

Namespace for the Aw library.

Examples:

Computes `6 * 7` in a sub-process and returns `42` to the current process.

Aw.fork! { 6 * 7 } # => 42

Defined Under Namespace

Classes: Fork

Class Method Summary collapse

Class Method Details

.fork!(&block) ⇒ #object_id

Runs the block inside a sub-process, and returns the computed value.

Examples:

Computes `6 * 7` in a sub-process and returns `42` to the current process.

fork! { 6 * 7 } # => 42

Parameters:

  • block (Proc)

    The code to run in a sub-process.

Returns:

  • (#object_id)

    The computed value.


18
19
20
21
# File 'lib/aw.rb', line 18

def self.fork!(&block)
  read, write = ::IO.pipe
  Fork.new(read, write).call(&block)
end