Sha256: 8e4b01545c042c9162c916e2963b0bc02f5bcb946c1fd907584ce15cf6528b7a
Contents?: true
Size: 897 Bytes
Versions: 3
Compression:
Stored size: 897 Bytes
Contents
require "async" require "async/semaphore" require "timeout" module Plumbing module Valve class Async attr_reader :target def initialize target @target = target @queue = [] @semaphore = ::Async::Semaphore.new(1) end # Ask the target to answer the given message def ask(message, *args, **params, &block) task = @semaphore.async do @target.send message, *args, **params, &block end Timeout.timeout(timeout) do task.wait end end # Tell the target to execute the given message def tell(message, *args, **params, &block) @semaphore.async do |task| @target.send message, *args, **params, &block rescue nil end nil end private def timeout Plumbing.config.timeout end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
standard-procedure-plumbing-0.3.3 | lib/plumbing/valve/async.rb |
standard-procedure-plumbing-0.3.2 | lib/plumbing/valve/async.rb |
standard-procedure-plumbing-0.3.1 | lib/plumbing/valve/async.rb |