-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
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
Labels
No labels