OneDoingTheRestWaiting - ODTRW 1.0.9
one-doing-the-rest-waiting
is a RPC helper using Kue package. It is made to handle long async tasks: first call is executed, other later calls will wait for repsonse of the first call.
Installation
npm install one-doing-the-rest-waiting
Example
// producer.jsconst rpc = ;const producer = rpc; producer;
// consumer.jsconst rpc = ;const consumer = rpc; consumer;
APIs
createProducer(config)
config
{Object} configuration for kue.createQueue()- return: a
Producer
instance
Factory method to create a Producer
instance
createConsumer(config)
config
{Object} configuration for kue.createQueue()- return: a
Consumer
instance
Factory method to create a Consumer
instance
producer.discover(callback)
callback
{Function} with parameterschannel
{ProducingChannel}
Find Consumer
instance with same Kue config
producingChannel.request(taskName, data, config)
taskName
{String}data
{Object} - optionalconfig
{Object} - optionalwaitFor
{String} Task identify to make other tasks waitttl
{Number} Time-to-live of this message (will be supported next version)
- return: a
Message
instance
message.waitFor(taskIdentify)
taskIdentify
- return: current
Message
instance
Sugar method to set config.waitFor
message.onResponse(callback)
callback
{Function} with paremetersresponse
{Object}
- return: current
Message
instance
Register callback that handles request's response
message.send()
Send the message
consumer.register(callback)
Register a Consumer
instance, let other Producer
s find it, with same Kue config
consumingChannel.onRequest(callback)
callback
{Function} with parametersrequest
{Object}done
{Function}
Register callback that handles requests