Project

aw

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Creates a sub-process to execute a block inside, and returns what it returns.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Aw

Version Yard documentation Ruby RuboCop License

Aw, fork 😬

Aw

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

Versioning

Aw follows Semantic Versioning 2.0.

License

The gem is available as open source under the terms of the MIT License.


This project is sponsored by:
Sashité