ruby - Why is the error `Celluloid::Condition signaled spuriously` caused in Celluloid? -
i'm trying wait on condition of async code, here's snippet:
condition = celluloid::condition.new rails.logger.debug "sending rpc request #{subject}" nats.start uri: env['nats_server'] rails.logger.debug "connected #{env['nats_server']}" sid = nats.request(subject,msg) |response| rails.logger.debug "assigning response" condition.signal response nats.stop end nats.timeout(sid, 1) nats.stop condition.signal async_error raise "one second timeout waiting nats rpc reply #{subject}" end end result = condition.wait if result = async_error raise "error in rpc call" else return result end i exception celluloid::condition signaled spuriously there's no information , don't understand why caused , https://github.com/celluloid/celluloid/wiki/conditions doesn't provide more information.
why caused , how can fix it?
and answer question stated question, using condition.
within scope of actor:
class nats include celluloid def initialize @condition = celluloid::condition.new end def start rails.logger.debug "sending rpc request #{subject}" nats.start uri: env['nats_server'] rails.logger.debug "connected #{env['nats_server']}" sid = nats.request(subject,msg) |response| rails.logger.debug "assigning response" @condition.signal response nats.stop end nats.timeout(sid, 1) nats.stop @condition.signal async_error raise "one second timeout waiting nats rpc reply #{subject}" end end end def value @condition.wait end end nats = nats.new nats.async.start result = nats.value if result = async_error raise "error in rpc call" else return result end this less tested, ought show basic approach if aren't going use future other answer.
Comments
Post a Comment