Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: TaskFlow #40

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Feat: TaskFlow #40

merged 1 commit into from
Mar 14, 2024

Conversation

aegenet
Copy link
Owner

@aegenet aegenet commented Mar 14, 2024

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

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

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();

… Awaiting version with FIFO (first in first out)
@aegenet aegenet added the enhancement New feature or request label Mar 14, 2024
@aegenet aegenet self-assigned this Mar 14, 2024
@aegenet aegenet merged commit b0a7602 into master Mar 14, 2024
5 checks passed
@aegenet aegenet deleted the feat-task-flow branch March 14, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant