https://github.com/fixrb/aw
Aw, fork 😬
https://github.com/fixrb/aw
ruby subprocess
Last synced: 6 months ago
JSON representation
Aw, fork 😬
- Host: GitHub
- URL: https://github.com/fixrb/aw
- Owner: fixrb
- License: mit
- Created: 2015-10-14T20:59:33.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T21:55:37.000Z (over 1 year ago)
- Last Synced: 2025-05-29T04:43:37.856Z (8 months ago)
- Topics: ruby, subprocess
- Language: Ruby
- Homepage:
- Size: 98.6 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Aw
[](https://github.com/fixrb/aw/tags)
[](https://rubydoc.info/github/fixrb/aw/main)
[](https://github.com/fixrb/aw/actions?query=workflow%3Aruby+branch%3Amain)
[](https://github.com/fixrb/aw/actions?query=workflow%3Arubocop+branch%3Amain)
[](https://github.com/fixrb/aw/raw/main/LICENSE.md)
> 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:
```ruby
gem "aw"
```
And then execute:
```sh
bundle install
```
Or install it yourself as:
```sh
gem install aw
```
## Usage
To make __Aw__ available:
```ruby
require "aw"
```
There are two methods:
- `fork!`
- `fork?`
### Method `.fork!`
Executes a block of code in a sub-process, and returns the result:
```ruby
Aw.fork! { 6 * 7 } # => 42
```
When the execution of a block of code causes side effects, these are limited to the sub-process:
```ruby
arr = ["foo"] # => ["foo"]
Aw.fork! { arr << "FUU" } # => ["foo", "FUU"]
arr # => ["foo"]
```
Exceptions raised in a block of code are propagated:
```ruby
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:
```ruby
Aw.fork? { 6 * 7 } # => true
```
When the execution of a block of code causes side effects, these are limited to the sub-process:
```ruby
arr = ["foo"] # => ["foo"]
Aw.fork? { arr << "FUU" } # => true
arr # => ["foo"]
```
When an exception is raised in a code block, `false` is returned:
```ruby
Aw.fork? { nil + 1 } # => false
```
## Contact
* Source code: https://github.com/fixrb/aw
## Versioning
__Aw__ follows [Semantic Versioning 2.0](https://semver.org/).
## License
The [gem](https://rubygems.org/gems/aw) is available as open source under the terms of the [MIT License](https://github.com/fixrb/aw/raw/main/LICENSE.md).
***
