Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/src/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export class Dispatcher<sync extends 'sync' | 'async'> {
callback: ResponseCallback,
): void {
// Call the callback but unsubscribe first
let calledCallback = false;
const callback_: ResponseCallback = (err, response) => {
if (calledCallback) return;
calledCallback = true;
this.unsubscribe();
return callback(err, response);
};
Expand All @@ -136,7 +139,20 @@ export class Dispatcher<sync extends 'sync' | 'async'> {
filter(message => message.message.case === 'compileResponse'),
map(message => message.message.value as OutboundResponse),
)
.subscribe({next: response => callback_(null, response)});
.subscribe({
next: response => callback_(null, response),
complete: () =>
// Wrap this in a setTimeout so that, if it's racing with
// `this.error$`, the error message wins.
setTimeout(
() =>
callback_(
new Error('Dispatcher closed before compilation completed'),
undefined,
),
0,
),
});

this.error$.subscribe({
error: error => callback_(error, undefined),
Expand Down
Loading