aantron / promise

Light and type-safe binding to JS promises
MIT License
341 stars 24 forks source link

Promise.pending/Promise.exec/Promise.resolved #77

Open davesnx opened 1 year ago

davesnx commented 1 year ago

Current API makes creating a Promise with .pending, which is fine and wrap a callback with exec, which is fine.

I would like to propose a similar API as the new Promise, such as:

let make (fn : resolve:('a -> unit) -> reject:(exn -> unit) -> unit) : 'a Promise.t

Which might make Promise.pending a little less used/useful. Promise.make () will eventually make a pending promise, until resolve is being called internally.

Note: The same interface can be found for ReScript Js.Promise, for example.


Another change to the API that I wanted to propose is

s/Promise.resolved/Promise.resolve

In order to keep familiarity with the callback version and the JavaScript version.