Sha256: 0a4c89d5c7f9a90e1d36eee009b89278fd56cb15ed10375993650c180eda2d0c
Contents?: true
Size: 914 Bytes
Versions: 2
Compression:
Stored size: 914 Bytes
Contents
require "async" require "async/semaphore" require "timeout" module Plumbing module Actor class Async attr_reader :target def initialize target @target = target @queue = [] @semaphore = ::Async::Semaphore.new(1) end # Send the message to the target and wrap the result def send_message(message_name, *, **, &) task = @semaphore.async do @target.send(message_name, *, **, &) end Result.new(task) end def safely(&) send_message(:perform_safely, &) nil end def in_context? = true def stop = nil Result = Data.define(:task) do def value Timeout.timeout(Plumbing::Actor.timeout) do task.wait end end end private_constant :Result end def self.timeout Plumbing.config.timeout end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
standard-procedure-plumbing-0.4.5 | lib/plumbing/actor/async.rb |
standard-procedure-plumbing-0.4.4 | lib/plumbing/actor/async.rb |