Skip to content

Commit

Permalink
fix: use uncurried mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DCKT committed Oct 27, 2023
1 parent 895052e commit 1b602df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion rescript.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dck/rescript-promise",
"uncurried": false,
"uncurried": true,
"namespace": false,
"sources": ["src/js"]
}
32 changes: 15 additions & 17 deletions src/js/promise.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This file is part of reason-promise, released under the MIT license. See
LICENSE.md for details, or visit
https://github.com/aantron/promise/blob/master/LICENSE.md. */

type rejectable<+'a, +'e>
type never

Expand Down Expand Up @@ -123,7 +119,7 @@ module Js_ = {

let allArray = promises => map(jsAll(promises), promises => Belt.Array.map(promises, unbox))

let all = promises => map(allArray(Belt.List.toArray(promises)), Belt.List.fromArray)
let all = promises => map(allArray(Belt.List.toArray(promises)), a => a->Belt.List.fromArray)

let all2 = (p1, p2) => jsAll((p1, p2))

Expand Down Expand Up @@ -265,34 +261,38 @@ let allOkArray = promises => {
huge lists of stale callbacks. This is also true of Promise.race, so we
rely on the quality of the runtime's Promise.race implementation to
proactively remove these callbacks. */
race(list{promise, callbackRemover}) |> (

(
wrapped =>
get(wrapped, result =>
switch result {
| Ok(v) =>
resultValues->Belt.Array.setExn(index, Some(v))
incr(resultCount)
if resultCount.contents >= promiseCount {
resultValues->Belt.Array.map(v =>
switch v {
| Some(v) => v
| None => assert false
}
) |> (values => resolve(Ok(values)))
(values => resolve(Ok(values)))(
resultValues->Belt.Array.map(
v =>
switch v {
| Some(v) => v
| None => assert(false)
},
),
)
}
| Error(e) =>
resolve(Error(e))
removeCallbacks(Error(e))
}
)
)
)(race(list{promise, callbackRemover}))
)

resultPromise
}
}

let allOk = promises => mapOk(allOkArray(Belt.List.toArray(promises)), Belt.List.fromArray)
let allOk = promises => mapOk(allOkArray(Belt.List.toArray(promises)), a => a->Belt.List.fromArray)

let unsafeAllOkArray = Obj.magic(allOkArray)

Expand Down Expand Up @@ -340,8 +340,6 @@ let tapSome = (promise, callback) => {
promise
}

module PipeFirst = {

}
module PipeFirst = {}

module Js = Js_

0 comments on commit 1b602df

Please sign in to comment.