Skip to content

Instantly share code, notes, and snippets.

@itspomf
itspomf / later.rb
Last active January 23, 2022 17:31
Ruby 3+ promise-like object
# Provides a Promise-like construct which can evaluate from a block, or method,
# and causes a caller to wait until it is resolved. Raising an error will
# cause the object to automatically resolve to the raised error; there is no
# need to invoke a callback.
class Later
# Internal thread context
attr :context
# Resultant or error
attr :value