Aw
Aw, fork 😬
Creates a sub-process to execute a block inside, and returns what it returns (or a boolean).
Installation
Add this line to your application's Gemfile:
gem "aw"
And then execute:
bundle install
Or install it yourself as:
gem install aw
Usage
To make Aw available:
require "aw"
There are two methods:
fork!
fork?
Method .fork!
Executes a block of code in a sub-process, and returns the result:
Aw.fork! { 6 * 7 } # => 42
When 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)
Method .fork?
Executes a block of code in a sub-process, and returns true
if no exception is thrown:
Aw.fork? { 6 * 7 } # => true
When 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
Contact
- Source code: https://github.com/fixrb/aw
Versioning
Aw follows Semantic Versioning 2.0.
License
The gem is available as open source under the terms of the MIT License.