Skip to content

Error on invalid dispose function. #162

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

Merged
merged 5 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/generators/disposable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import that from "../that.js";

export default function disposable(value, dispose) {
let done = false;
if (typeof dispose !== "function") {
throw new Error("dispose is not a function");
}
return {
[Symbol.iterator]: that,
next: () => done ? {done: true} : (done = true, {done: false, value}),
Expand Down
6 changes: 6 additions & 0 deletions src/generators/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export default function(initialize) {
let resolve;
const dispose = initialize(change);

if (dispose != null && typeof dispose !== "function") {
throw new Error(typeof dispose.then === "function"
? "async initializers are not supported"
: "initializer returned something, but not a dispose function");
}

function change(x) {
if (resolve) resolve(x), resolve = null;
else stale = true;
Expand Down
6 changes: 6 additions & 0 deletions src/generators/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default function(initialize) {
const queue = [];
const dispose = initialize(push);

if (dispose != null && typeof dispose !== "function") {
throw new Error(typeof dispose.then === "function"
? "async initializers are not supported"
: "initializer returned something, but not a dispose function");
}

function push(x) {
queue.push(x);
if (resolve) resolve(queue.shift()), resolve = null;
Expand Down