Skip to content

Allow to set a debounce rate for messages #29

@christian-bromann

Description

@christian-bromann

Let's say we have the following use case:

import Channel from 'tangle/worker_threads';

interface TodoList {
    todos: string[]
    dueDate: number
}

const ch = new Channel<TodoList>('foobar', {
    todos: [],
    dueDate: Date.now()
});

and given we update the state with two separate calls, e.g.:

ch.broadcast({ dueDate: Date.now() });
ch.broadcast({ todos: [{...}] });

If someone listens on todos, this would cause two event listener executions, one with no updates, the other with the updated todos. This is bad for performance for two reasons: 1) a state update is triggered without an update to the state, 2) multiple individual updates trigger individual event listener executions.

To improve this behavior I suggest to:

  • only broadcast updates if a state property has changed
  • allow to set up a debounce rate so tangle collects changes over x amount of time and broadcast the current state after the debounce limit is reached

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions