empReflect
Async Server/Client Command Interface. Designed for Empati.
// Generates function for sending commands // this -> this object which will be binded to SenderFunction // SenderFunction -> Takes Command object and sends to receiver. If can't transport object should stringify first. // Id -> Uniq id for generated function. Used for distinguishing owner of messages. // Return: function(Command, ...Args) {...} // First Param which function in receiver will triggered and rest of the parameters will be given as arguments to triggered function.
// Generates function for running received commands and send results back // this -> this object which will be binded to SenderFunction // SenderFunction -> Takes Command object and sends to receiver. If can't transport object should stringify first. // Commands -> An object full of functions which will triggered when you get a command. // Return: function(CommandObj) {...} // Generated function takes a Command Object sent by Send function and // after processing returns the result via sender function
Example Usage
var empReflect = const cluster = ; const main = { ifclusterisMaster forlet i = 0; i < 4; i++ const worker = cluster; workerSend = empReflect; worker; else processSend = empReflect; process; const C1 = await process; const C2 = await process; console; } ;