Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

fix(worker): correctly emit falsy values sent by the ServiceWorker #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 2 additions & 5 deletions service-worker/worker/src/companion/comm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import 'rxjs/add/operator/reduce';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/takeWhile';

function fromPromise<T>(promiseFn: (() => Promise<T>)): Observable<T> {
return Observable.create(observer => {
Expand Down Expand Up @@ -119,7 +118,7 @@ export class NgServiceWorker {
err => this.controllingWorker.error(err),
() => this.controllingWorker.complete(),
);

// To make one-off calls to the worker, awaitSingleControllingWorker waits for
// a controlling worker to exist.
this.awaitSingleControllingWorker = this
Expand Down Expand Up @@ -172,8 +171,6 @@ export class NgServiceWorker {
this.sendToWorker(worker, {cmd: 'cancel', id: cancelId});
};
})
// Instead of complicating this with 'close' events, complete on a null value.
.takeWhile(v => !!v)
// The message will be sent before the consumer has a chance to subscribe to
// the response Observable, so publishReplay() records any responses and ensures
// they arrive properly.
Expand All @@ -199,7 +196,7 @@ export class NgServiceWorker {
// Wait for a controlling worker to exist.
.awaitSingleControllingWorker
// Send the message and await any replies. switchMap is chosen so if a new
// controlling worker arrives somehow, the message will still get through.
// controlling worker arrives somehow, the message will still get through.
.switchMap(worker => this.sendToWorker(worker, message));
}

Expand Down