Using Concurrent::Promise while rescuing exceptions in Ruby

This page summarizes the projects mentioned and recommended in the original post on dev.to

Sevalla - Deploy and host your apps and databases, now with $50 credit!
Sevalla is the PaaS you have been looking for! Advanced deployment pipelines, usage-based pricing, preview apps, templates, human support by developers, and much more!
sevalla.com
featured
InfluxDB – Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com
featured
  1. Concurrent Ruby

    Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.

    As I could not find a clear example about how to rescue exceptions from Concurrent::Promises (part of the Concurrent Ruby gem ) I read through the documentation and here are two examples: one that documents success case and one that shows what is happening when there is an error.

  2. Sevalla

    Deploy and host your apps and databases, now with $50 credit! Sevalla is the PaaS you have been looking for! Advanced deployment pipelines, usage-based pricing, preview apps, templates, human support by developers, and much more!

    Sevalla logo
  3. rubygems

    Library packaging and distribution for Ruby.

    require 'bundler/inline' gemfile do ruby "3.0.1" source 'https://rubygems.org' gem "concurrent-ruby" end require "concurrent" require "pp" # Just a simple class that needs to execute something class Load def initialize(id) @id = id end def work exception = [MyException, SecondException].sample raise exception.send(:new) end end class MyException < Exception ; end class SecondException < Exception ; end class ParallelExecution def call # Using here Concurrent::Array to be thread safe exceptions = Concurrent::Array.new promises = [] 10.times do |t| promises << Concurrent::Promises.future { Load.new(t).work }.rescue { exceptions.push(_1) } end # Calling .value on each job to wait for its execution values = Concurrent::Promises.zip(*promises).value # Raising exceptions if any of the jobs were returning an exception if exceptions.length > 0 count_my_exception = exceptions.count { _1.instance_of?(MyException) } count_second_exception = exceptions.count { _1.instance_of?(SecondException) } puts "MyException generated #{count_my_exception}" puts "SecondException generated #{count_second_exception}" end end end ParallelExecution.new.call

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Rv, a new kind of Ruby management tool

    1 project | news.ycombinator.com | 26 Aug 2025
  • Developing Modules for Puppet and the Forge in 2025

    2 projects | dev.to | 30 Jul 2025
  • Joy of Test Driven Development(TDD) using Rspec in Ruby

    1 project | dev.to | 28 May 2025
  • Go Tool: tudo o que ninguem pediu

    2 projects | dev.to | 5 Apr 2025
  • Re-Revisiting Performance in Ruby 3.4.1

    1 project | dev.to | 25 Mar 2025

Did you know that Ruby is
the 12th most popular programming language
based on number of references?