@aegenet/belt-task-flow
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

npm version

@aegenet/belt-task-flow

Enables loosely coupled publish/subscribe messaging. Awaiting version with FIFO (first in first out)

💾 Installation

yarn add @aegenet/belt-task-flow@^2.0.0
# or
npm i @aegenet/belt-task-flow@^2.0.0

📝 Usage

TaskFlow

import { TaskFlow, type ITaskFlow } from '@aegenet/belt-task-flow';

const taskFlow: ITaskFlow = new TaskFlow();

const tabs: string[] = [];

taskFlow.subscribe('Something', async () => {
  await delay(200);
  tabs.push('with delay');
});

taskFlow!.subscribe('Something', () => {
  tabs.push('without delay');
});


await taskFlow!.publish('Something');

// tabs => ['with delay', 'without delay']

await taskFlow!.publish('Something');

// tabs => ['with delay', 'without delay', 'with delay', 'without delay']

taskFlow.dispose();

Listener & subscription

Note: Stage 3 decorator (for stage 2, you can use an older version (< 2.0.0) of this package).

import { TaskFlow, type ITaskFlow, TaskFlowListener, taskFlowMethod } from '@aegenet/belt-task-flow';

const taskFlow: ITaskFlow = new TaskFlow();

class ListenToMe extends TaskFlowListener {
    public msg: string[] = [];

    constructor() {
      super(taskFlow!);
    }

    @taskFlowMethod()
    public doIt() {
      this.msg.push('hello');
    }
}

// [...]
const listenToMe = new ListenToMe();

// publish
await taskFlow!.publish('tf.ListenToMe:doIt');
// listenToMe.msg => ['hello']

// [...]
listenToMe.dispose();
taskFlow.dispose();

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @aegenet/belt-task-flow

      Weekly Downloads

      50

      Version

      2.1.0

      License

      MIT

      Unpacked Size

      22.1 kB

      Total Files

      7

      Last publish

      Collaborators

      • agenet