it("works with @wry/context", function () { const nameSlot = new Slot<string>(); function withName<T = any>(name: string, exec: (task: Task<T>) => void) { return new Task<T>(task => nameSlot.withValue(name, () => exec(task))); } return withName("parent", task => { assert.strictEqual(nameSlot.getValue(), "parent"); task.resolve(123); }).then(oneTwoThree => withName("child", child => { assert.strictEqual(nameSlot.getValue(), "child"); const sibling = withName("sibling", task => { task.resolve(nameSlot.getValue()); }).then(result => { assert.strictEqual(result, "sibling"); assert.strictEqual(nameSlot.getValue(), "child"); }); setTimeout(() => { assert.strictEqual(nameSlot.getValue(), "child"); child.resolve(withName("grandchild", grandchild => { assert.strictEqual(nameSlot.getValue(), "grandchild"); sibling.then(() => { assert.strictEqual(nameSlot.getValue(), "grandchild"); grandchild.resolve(oneTwoThree); }, grandchild.reject); })); }, 10); })).then(result => { assert.strictEqual(nameSlot.hasValue(), false); assert.strictEqual(result, 123); }); });
child.resolve(withName("grandchild", grandchild => { assert.strictEqual(nameSlot.getValue(), "grandchild"); sibling.then(() => { assert.strictEqual(nameSlot.getValue(), "grandchild"); grandchild.resolve(oneTwoThree); }, grandchild.reject); }));
}).then(oneTwoThree => withName("child", child => { assert.strictEqual(nameSlot.getValue(), "child"); const sibling = withName("sibling", task => { task.resolve(nameSlot.getValue()); }).then(result => { assert.strictEqual(result, "sibling"); assert.strictEqual(nameSlot.getValue(), "child"); }); setTimeout(() => { assert.strictEqual(nameSlot.getValue(), "child"); child.resolve(withName("grandchild", grandchild => { assert.strictEqual(nameSlot.getValue(), "grandchild"); sibling.then(() => { assert.strictEqual(nameSlot.getValue(), "grandchild"); grandchild.resolve(oneTwoThree); }, grandchild.reject); })); }, 10); })).then(result => {
})).then(result => { assert.strictEqual(nameSlot.hasValue(), false); assert.strictEqual(result, 123); });
}).then(result => { assert.strictEqual(result, "sibling"); assert.strictEqual(nameSlot.getValue(), "child"); });
const sibling = withName("sibling", task => { task.resolve(nameSlot.getValue()); }).then(result => {
return withName("parent", task => { assert.strictEqual(nameSlot.getValue(), "parent"); task.resolve(123); }).then(oneTwoThree => withName("child", child => {
return new Task<T>(task => nameSlot.withValue(name, () => exec(task)));