Aw, fork 😬
Creates a sub-process to execute a block inside, and returns what it returns (or a boolean).
Add this line to your application's Gemfile:
gem "aw"And then execute:
bundle installOr install it yourself as:
gem install awTo make Aw available:
require "aw"There are two methods:
fork!fork?
Executes a block of code in a sub-process, and returns the result:
Aw.fork! { 6 * 7 } # => 42When the execution of a block of code causes side effects, these are limited to the sub-process:
arr = ["foo"] # => ["foo"]
Aw.fork! { arr << "FUU" } # => ["foo", "FUU"]
arr # => ["foo"]Exceptions raised in a block of code are propagated:
Aw.fork! { nil + 1 }results in the error:
NoMethodError(undefined method `+' for nil:NilClass)
Executes a block of code in a sub-process, and returns true if no exception is thrown:
Aw.fork? { 6 * 7 } # => trueWhen the execution of a block of code causes side effects, these are limited to the sub-process:
arr = ["foo"] # => ["foo"]
Aw.fork? { arr << "FUU" } # => true
arr # => ["foo"]When an exception is raised in a code block, false is returned:
Aw.fork? { nil + 1 } # => false- Source code: https://github.com/fixrb/aw
Aw follows Semantic Versioning 2.0.
The gem is available as open source under the terms of the MIT License.

