Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Promise.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ let catch = (promise, callback) => {

@bs.scope("Promise") @bs.val
external race: array<t<'a>> => t<'a> = "race"

external done: Js.Promise.t<'a> => unit = "%ignore"
9 changes: 7 additions & 2 deletions src/Promise.resi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ In case you want to return another promise in your `callback`, consider using \`
let catch: (t<'a>, exn => t<'a>) => t<'a>

@ocaml.doc("
`then(promise, callback)` returns a new promise based on the result of `promise`'s value.
`then(promise, callback)` returns a new promise based on the result of `promise`'s value.
The `callback` needs to explicitly return a new promise via `resolve`.

It is **not allowed** to resolve a nested promise (like `resolve(resolve(1))`).
Expand All @@ -120,7 +120,7 @@ Promise.resolve(5)
external then: (t<'a>, @uncurry ('a => t<'b>)) => t<'b> = "then"

@ocaml.doc("
`thenResolve(promise, callback)` converts an encapsulated value of a promise into another promise wrapped value.
`thenResolve(promise, callback)` converts an encapsulated value of a promise into another promise wrapped value.

It is **not allowed** to return a promise within the provided callback (e.g. `thenResolve(value => resolve(value))`).

Expand Down Expand Up @@ -234,3 +234,8 @@ external all5: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>)) => t<('a, 'b, 'c, 'd, 'e)>
@bs.scope("Promise")
@bs.val
external all6: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>, t<'f>)) => t<('a, 'b, 'c, 'd, 'e, 'f)> = "all"

@ocaml.doc("
`done` is a safe way to ignore a promise. If a value is anything else than a promise, it will raise a type error.
")
external done: Js.Promise.t<'a> => unit = "%ignore"
3 changes: 1 addition & 2 deletions tests/PromiseTest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions tests/PromiseTest.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Creation = {
Test.run(__POS_OF__("Should resolve test"), str, equal, "test")
resolve()
})
->ignore
->done
}

let runTests = () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ module ThenChaining = {
Test.run(__POS_OF__("Should be 2"), value, equal, 2)
resolve()
})
->ignore
->done
resolve()
})
->catch(e => {
Expand Down Expand Up @@ -94,7 +94,7 @@ module ThenChaining = {
->thenResolve(num => {
num + 1
})
->ignore
->done
resolve()
})
->catch(e => {
Expand All @@ -108,10 +108,10 @@ module ThenChaining = {
}

let runTests = () => {
testThen()->ignore
testInvalidThen()->ignore
testThenResolve()->ignore
testInvalidThenResolve()->ignore
testThen()->Promise.done
testInvalidThen()->Promise.done
testThenResolve()->Promise.done
testInvalidThenResolve()->Promise.done
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ module Catching = {
Test.run(__POS_OF__("finally should have been called"), wasCalled.contents, equal, true)
resolve()
})
->ignore
->done
}

let testResolveFinally = () => {
Expand All @@ -267,16 +267,16 @@ module Catching = {
Test.run(__POS_OF__("finally should have been called"), wasCalled.contents, equal, true)
resolve()
})
->ignore
->done
}

let runTests = () => {
testExternalPromiseThrow()->ignore
testExnThrow()->ignore
testRaiseErrorThrow()->ignore
thenAfterCatch()->ignore
testCatchFinally()->ignore
testResolveFinally()->ignore
testExternalPromiseThrow()->Promise.done
testExnThrow()->Promise.done
testRaiseErrorThrow()->Promise.done
thenAfterCatch()->Promise.done
testCatchFinally()
testResolveFinally()
}
}

Expand Down