diff --git a/sdk/nodejs/runtime/property.ts b/sdk/nodejs/runtime/property.ts index 542b0591f..7081921d0 100644 --- a/sdk/nodejs/runtime/property.ts +++ b/sdk/nodejs/runtime/property.ts @@ -47,7 +47,7 @@ export class Property implements Computed { } // mapValue attaches a callback for the resolution of a computed value, and returns a newly computed value. - public mapValue(callback: (v: T) => U): Computed { + public mapValue(callback: (v: T) => U | Computed): Computed { let result = new Property(); this.outputPromise.then((value: T | undefined) => { // If the value is unknown, propagate an unknown. Otherwise, use the callback to compute something new. @@ -55,7 +55,23 @@ export class Property implements Computed { result.setOutput(undefined, true, false); } else { - result.setOutput(callback(value), true, false); + try { + // There's a callback; invoke it. + let u: U | Computed = callback(value); + + // If this is another computed, we need to wire up to its resolution; else just store the value. + if ((u as Computed).mapValue) { + (u as Computed).mapValue((v: U) => { + result.setOutput(v, true, false); + }); + } + else { + result.setOutput(u, true, false); + } + } + catch (err) { + Log.error(`MapValue of a Computed yielded an unhandled error: ${err}`); + } } }); return result;