Project

iopromise

0.0
No release in over a year
This gem extends promise.rb promises to support an extremely simple pattern for "continuing" execution of the promise in an asynchronous non-blocking way.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.7.4
>= 0
 Project Readme

IOPromise

IOPromise is a pattern that allows parallel execution of IO-bound requests (data store and RPCs) behind the abstraction of promises, without needing to introduce the complexity of threading. It uses promise.rb for promises, and nio4r to implement the IO loop.

A simple example of this behaviour is using iopromise-faraday to perform concurrent HTTP requests:

require 'iopromise/faraday'

conn = IOPromise::Faraday.new('https://github.com/')

promises = (1..3).map do
  conn.get('/status')
end

Promise.all(promises).then do |responses|
  responses.each_with_index do |response, i|
    puts "#{i}: #{response.body.strip} #{response.headers["x-github-request-id"]}"
  end
end.sync

Installation

Add this line to your application's Gemfile:

gem 'iopromise'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install iopromise

Usage

IOPromise itself is a base library that makes it easy to wrap other IO-based workloads inside a promise-based API that back to an event loop. To use IOPromise, look at the following gems:

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/theojulienne/iopromise. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the iopromise project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.