Skip to content

Commit

Permalink
Add Observable.empty; bump to v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecsl committed Dec 15, 2021
1 parent 4e31f3a commit 18e16f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obgen",
"version": "0.1.1",
"version": "0.1.2",
"description": "Javascript Observables implemented with async generators",
"main": "dist/observable.js",
"types": "dist/observable.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export default class Observable<T> {
});
}

/** Returns a new empty `Observable`, which emits no items and ends immediately. */
static empty<T>(): Observable<T> {
return Observable.create((stream) => stream.end());
}

/**
* Creates an `Observable` that, upon subscription, emits the provided value `val` and ends
* immediately.
Expand Down
6 changes: 6 additions & 0 deletions src/test/observable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe("Observable", () => {
expect(await observable.toArray()).toEqual([[1]]);
});
});
describe("#empyt", () => {
it("should emit no items", async () => {
const observable = Observable.empty();
expect(await observable.toArray()).toEqual([]);
});
});
describe("#defer", () => {
it("should resolve promise upon subscription", async () => {
const arr = [1];
Expand Down

0 comments on commit 18e16f4

Please sign in to comment.