Skip to content
Closed
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
5 changes: 3 additions & 2 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ function module_variable(observer) {
return new Variable(TYPE_NORMAL, this, observer);
}

function module_value(name) {
async function module_value(name) {
var v = this._scope.get(name);
if (!v) throw new RuntimeError(name + " is not defined");
if (v._observer === no_observer) {
v._observer = true;
this._runtime._dirty.add(v);
}
return this._runtime._compute().then(() => v._promise);
await this._runtime._compute();
return v._promise;
}

function module_derive(injects, injectModule) {
Expand Down
12 changes: 12 additions & 0 deletions test/module/value-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ tape("module.value(name) supports missing variables", async test => {
}
});

tape("module.value(name) returns a promise on error", async test => {
const runtime = new Runtime();
const module = runtime.module();
const promise = module.value("bar");
try {
await promise;
test.fail();
} catch (error) {
test.deepEqual(error.message, "bar is not defined");
}
});

tape("module.value(name) does not force recomputation", async test => {
let foo = 0;
const runtime = new Runtime();
Expand Down