Skip to content

Commit

Permalink
feat: loosen watcher type guards to support non-passables
Browse files Browse the repository at this point in the history
Co-authored-by: Michael FIG <[email protected]>
  • Loading branch information
0xpatrickdev and michaelfig committed Sep 16, 2024
1 parent e67cd91 commit efaeb1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vow/src/watch-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const prepareWatchUtils = (
asPromise: M.call(M.raw()).rest(M.raw()).returns(M.promise()),
}),
watcher: M.interface('Watcher', {
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
onFulfilled: M.call(M.raw()).rest(M.raw()).returns(M.raw()),
onRejected: M.call(M.raw()).rest(M.raw()).returns(M.raw()),
}),
retryRejectionPromiseWatcher: PromiseWatcherI,
},
Expand Down
16 changes: 16 additions & 0 deletions packages/vow/test/watch-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,19 @@ test('asPromise handles watcher arguments', async t => {
t.is(result, 'watcher test');
t.true(watcherCalled);
});

test('allVows handles unstorable results', async t => {
const zone = makeHeapZone();
const { watch, when, allVows } = prepareBasicVowTools(zone);

const nonPassable = () => 'i am a function';

const specimenA = Promise.resolve('i am a promise');
const specimenB = watch(nonPassable);

const result = await when(allVows([specimenA, specimenB]));
t.is(result.length, 2);
t.is(result[0], 'i am a promise');
t.is(result[1], nonPassable);
t.is(result[1](), 'i am a function');
});

0 comments on commit efaeb1c

Please sign in to comment.