-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds asVow() helper function that coerces the result of a function to a Vow - see comment from @mhofman for inspiration: #9454 (comment)
- Loading branch information
1 parent
3aa5d66
commit b6b5f5f
Showing
4 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @ts-check | ||
import test from 'ava'; | ||
|
||
import { makeHeapZone } from '@agoric/base-zone/heap.js'; | ||
|
||
import { prepareVowTools } from '../src/tools.js'; | ||
import { isVow } from '../src/vow-utils.js'; | ||
|
||
test('asVow takes a function that throws/returns synchronously and returns a vow', async t => { | ||
const zone = makeHeapZone(); | ||
const { watch, when, asVow } = prepareVowTools(zone); | ||
|
||
const fnThatThrows = () => { | ||
throw Error('fail'); | ||
}; | ||
|
||
const vowWithRejection = asVow(fnThatThrows); | ||
t.true(isVow(vowWithRejection)); | ||
await t.throwsAsync(when(vowWithRejection), { message: 'fail' }, 'failure '); | ||
|
||
const isWatchAble = watch(asVow(fnThatThrows)); | ||
t.true(isVow(vowWithRejection)); | ||
await t.throwsAsync(when(isWatchAble), { message: 'fail' }, 'failure '); | ||
|
||
const fnThatReturns = () => { | ||
return 'early return'; | ||
}; | ||
const vowWithReturn = asVow(fnThatReturns); | ||
t.true(isVow(vowWithReturn)); | ||
t.is(await when(vowWithReturn), 'early return'); | ||
t.is(await when(watch(vowWithReturn)), 'early return'); | ||
}); |