Inconsistent order of events
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 6.5k
- Forks
- 456
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
Currently many events are emitted synchronously in response to local function calls, for example submitOp emits an op event synchronously. This leads to some unexpected behaviours, for example:
doc.on((op, source) => { if (source === '1') submitOp(op1, '2') })
doc.on((op, source) => console.log(source))
doc.submitOp(op1, '1')
prints:
2
1
instead of:
1
2
which reflects the actual order of operations.
Here's what happens in the example above:
op1is submitted.- An
'op'event is emitted with source'1'. - The first handler is called with source
'1'and submitsop2. - An
'op'event is emitted with source'2'. - The first handler is called with source
'2'and exits. - The second handler is called with source
'2'and prints it. - The second handler is called with source
'1'and prints it.
In order to deal with this issue perhaps we could use an approach similar to MutationObserver, where synchronous operations are recorded in an Array and then a single event is emitted asynchronously with the list as a parameter?
Related issues:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing submitOp and the synchronous 'op' event handlers in the example, then read the linked issue 206 and pull request 129 alongside the MutationObserver reference. The work is done only when the intended event and callback ordering is agreed and the behavior is consistently defined for nested submissions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100