Function
Static Public Summary | ||
public |
Create a function that evaluates a tagged template to create a new subclass of FogletProtocol that implements the protocol described in the template. |
Static Public
public define(protocolName: string): function source
import define from 'foglet-core/src/fprotocol/protocol-builder.js'
Create a function that evaluates a tagged template to create a new subclass of FogletProtocol that implements the protocol described in the template.
Params:
Name | Type | Attribute | Description |
protocolName | string | The name of the protocol |
Return:
function | A function that evaluates a tagged template to create a new subclass of FogletProtocol |
Example:
const ExampleUnicastProtocol = defineProtocol('example-unicast-protocol')`
init
${function (base) {
this._base = base;
}}
get
${function(service) {
service.is.unicast();
service.on.receive(function (id, msg, reply, reject) {
if (msg.number % this._base === 0)
reply(`${msg.number} is a multiple of ${this._base}`);
else
reject(`${msg.number} is not a multiple of ${this._base}`);
});
}}
`;
export default ExampleUnicastProtocol;