Home Reference Source

Function

Static Public Summary
public

define(protocolName: string): function

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

Create a function that evaluates a tagged template to create a new subclass of FogletProtocol that implements the protocol described in the template.

Params:

NameTypeAttributeDescription
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;