-
Notifications
You must be signed in to change notification settings - Fork 83
refactor: Made PendingEventsStore interface asynchronous #513
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
Changes from all commits
4b59b0a
9a1d513
8a9b9c3
c8e05b2
a84e27b
8c63727
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,23 +53,21 @@ export class PendingEventsDispatcher implements EventDispatcher { | |
} | ||
|
||
sendPendingEvents(): void { | ||
const pendingEvents = this.store.values() | ||
|
||
logger.debug('Sending %s pending events from previous page', pendingEvents.length) | ||
|
||
pendingEvents.forEach(item => { | ||
try { | ||
this.send(item, () => {}) | ||
} catch (e) {} | ||
this.store.values().then((pendingEvents) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
logger.debug('Sending %s pending events from previous page', pendingEvents.length) | ||
pendingEvents.forEach(item => { | ||
try { | ||
this.send(item, () => {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does MAP guarantee the fifo order in JS? Otherwise, we lose the order of events dispatched. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, orders are concerned in other cases as well:
|
||
} catch (e) {} | ||
}) | ||
}) | ||
} | ||
|
||
protected send(entry: DispatcherEntry, callback: EventDispatcherCallback): void { | ||
this.store.set(entry.uuid, entry) | ||
|
||
this.dispatcher.dispatchEvent(entry.request, response => { | ||
this.store.remove(entry.uuid) | ||
callback(response) | ||
this.store.set(entry.uuid, entry).then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above RE: doing things after close: If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed this offline w/Zeeshan - this part is OK as-is, disregard. |
||
this.dispatcher.dispatchEvent(entry.request, response => { | ||
this.store.remove(entry.uuid).then(() => callback(response)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need a protection from one packet stuck in the queue forever (cannot send to the server successfully for JSON format error etc). This can be an issue when we change them in FIFO order. |
||
}) | ||
}) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this
setTimeout
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because i want to detect call
dispatchEvent
on the original event dispatcher which was called synchronously earlier but now its being called asynchronously after theset
promise resolves.