Skip to content

Commit 81e330e

Browse files
ghivertlpil
authored andcommitted
Add documentation for promise.race_*
1 parent cac3386 commit 81e330e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/gleam/javascript/promise.gleam

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import gleam/javascript/array.{type Array}
77
///
88
/// This library assumes you have some familiarity with JavaScript promises. If
99
/// you are not then you may want to take the time to learn about them outside of
10-
/// Gleam.
10+
/// Gleam.
1111
///
1212
/// The Gleam promise type is generic over the type of value it resolves. It is
1313
/// not generic over the error type as any Gleam panic or JavaScript exception
14-
/// could alter the error value in an way that undermines the type, making it
14+
/// could alter the error value in an way that undermines the type, making it
1515
/// unsound and untypable.
1616
/// If you want to represent success and failure with promises use a Gleam
1717
/// `Result` inside of a promise.
1818
///
19-
/// For further information view the MDN documentation:
19+
/// For further information view the MDN documentation:
2020
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>
2121
///
2222
pub type Promise(value)
@@ -123,15 +123,17 @@ pub fn try_await(
123123
/// Chain an asynchronous operation onto an array of promises, so it runs after the
124124
/// promises have resolved.
125125
///
126-
/// This is the equivilent of the `Promise.all` JavaScript static method.
126+
/// This is the equivilent of the [`Promise.all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
127+
/// JavaScript static method.
127128
///
128129
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
129130
pub fn await_array(a: Array(Promise(a))) -> Promise(Array(a))
130131

131132
/// Chain an asynchronous operation onto an list of promises, so it runs after the
132133
/// promises have resolved.
133134
///
134-
/// This is the equivilent of the `Promise.all` JavaScript static method.
135+
/// This is the equivilent of the [`Promise.all`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
136+
/// JavaScript static method.
135137
///
136138
pub fn await_list(xs: List(Promise(a))) -> Promise(List(a)) {
137139
xs
@@ -142,9 +144,21 @@ pub fn await_list(xs: List(Promise(a))) -> Promise(List(a)) {
142144
@external(javascript, "../../gleam_javascript_ffi.mjs", "all_promises")
143145
fn do_await_list(a: List(Promise(a))) -> Promise(Array(a))
144146

147+
/// Wait for the first promise to settle. Any promise settling after the
148+
/// first one is ignored.
149+
///
150+
/// This is the equivalent of the [`Promise.race`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
151+
/// JavaScript static method.
152+
///
145153
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
146154
pub fn race_list(a: List(Promise(a))) -> Promise(a)
147155

156+
/// Wait for the first promise to settleAny promise settling after the
157+
/// first one is ignored.
158+
///
159+
/// This is the equivalent of the [`Promise.race`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
160+
/// JavaScript static method.
161+
///
148162
@external(javascript, "../../gleam_javascript_ffi.mjs", "race_promises")
149163
pub fn race_array(a: Array(Promise(a))) -> Promise(a)
150164

0 commit comments

Comments
 (0)