Git Product home page Git Product logo

async_ruby's Introduction

async_ruby

Demonstrates the use of the async gem in Ruby 2.7 and 3.0. Based on the code examples in https://brunosutic.com/blog/async-ruby

Installation

$ bundle install

Running

Set your local Ruby version to 2.7.x or 3.0.x, then:

$ bin/run

Output

You should see something like:

$ rbenv local 2.7.4

$ bin/run
Ruby 2.7.4
URI.open duration: 3.734776
Async::HTTP duration: 1.86563

$ rbenv local 3.0.2

$ bin/run
Ruby 3.0.2
URI.open duration: 1.82335
Async::HTTP duration: 1.846074

Note that in Ruby 2.7, the async-http gem runs asynchronously, but URI.open runs synchronously. But in Ruby 3.0, both run asynchronously. This is because, as the article writes,

Async Ruby was created by Samuel Williams, who is also a Ruby core committer. Samuel also implemented "fiber scheduler", a big Ruby 3.0 feature. It's "library agnostic" and may have other uses in the future, but currently, the main purpose of fiber scheduler is to enable seamless integration of async gem with Ruby.

In other words, in Ruby 2.7 you have to explicitly use async-compatible gems. But in Ruby 3,

any blocking operation (a method where Ruby interpreter waits) is compatible with Async and will work asynchronously within Async code block with Ruby 3.0 and later.

async_ruby's People

Contributors

codingitwrong avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.