Skip to content

Js.Promise -> Js.Promise2 #3313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2019
Merged
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
5 changes: 3 additions & 2 deletions jscomp/others/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ build others/js_null_undefined.cmi : cc others/js_null_undefined.mli | runtime
build others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.ml | runtime
build others/js_option.cmj : cc others/js_option.ml | others/js_exn.cmj others/js_option.cmi runtime
build others/js_option.cmi : cc others/js_option.mli | runtime
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | runtime
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | others/js_promise2.cmj runtime
build others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.ml | runtime
build others/js_re.cmi : cc others/js_re.mli | others/js_re2.cmi runtime
build others/js_re2.cmi : cc others/js_re2.mli | runtime
build others/js_result.cmj : cc others/js_result.ml | others/js_result.cmi runtime
Expand All @@ -121,7 +122,7 @@ build others/js_undefined.cmj : cc others/js_undefined.ml | others/js_exn.cmj ot
build others/js_undefined.cmi : cc others/js_undefined.mli | runtime
build others/js_vector.cmj : cc others/js_vector.ml | others/js_vector.cmi runtime
build others/js_vector.cmi : cc others/js_vector.mli | runtime
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
build others/belt_Array.cmj : cc others/belt_Array.ml | others/belt.cmi others/belt_Array.cmi others/js_math.cmj js_pkg runtime
build others/belt_Array.cmi : cc others/belt_Array.mli | runtime
build others/belt_Debug.cmi others/belt_Debug.cmj : cc others/belt_Debug.ml | runtime
Expand Down
14 changes: 7 additions & 7 deletions jscomp/others/js_promise.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
]}
*)

type + 'a t
type error (* abstract error type *)
type + 'a t = 'a Js_promise2.t
type error = Js_promise2.error


external make : (resolve:('a -> unit [@bs]) ->
Expand All @@ -53,17 +53,17 @@ external then_ : ('a -> 'b t [@bs.uncurry]) -> 'b t = "then" [@@bs.send.pipe: 'a

external catch : (error -> 'a t [@bs.uncurry]) -> 'a t = "catch" [@@bs.send.pipe: 'a t]
(* [ p|> catch handler]
Note in JS the returned promise type is actually runtime dependent,
if promise is rejected, it will pick the [handler] otherwise the original promise,
Note in JS the returned promise type is actually runtime dependent,
if promise is rejected, it will pick the [handler] otherwise the original promise,
to make it strict we enforce reject handler
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
*)


(*
let errorAsExn (x : error) (e : (exn ->'a option))=
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
e (Obj.magic x)
let errorAsExn (x : error) (e : (exn ->'a option))=
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
e (Obj.magic x)
else None
[%bs.error? ]
*)
69 changes: 69 additions & 0 deletions jscomp/others/js_promise2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

(** Specialized bindings to Promise. Note: For simplicity,
this binding does not track the error type, it treat it as an opaque type
{[

]}
*)

type + 'a t
type error (* abstract error type *)


external make : (resolve:('a -> unit [@bs]) ->
reject:(exn -> unit [@bs]) -> unit [@bs.uncurry]) -> 'a t = "Promise" [@@bs.new]
(* [make (fun resolve reject -> .. )] *)
external resolve : 'a -> 'a t = "resolve" [@@bs.val] [@@bs.scope "Promise"]
external reject : exn -> 'a t = "reject" [@@bs.val] [@@bs.scope "Promise"]
external all : 'a t array -> 'a array t = "all" [@@bs.val] [@@bs.scope "Promise"]
external all2 : 'a0 t * 'a1 t -> ('a0 * 'a1) t = "all" [@@bs.val] [@@bs.scope "Promise"]
external all3 : 'a0 t * 'a1 t * 'a2 t -> ('a0 * 'a1 * 'a2 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
external all4 : 'a0 t * 'a1 t * 'a2 t * 'a3 t -> ('a0 * 'a1 * 'a2 * 'a3 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
external all5 : 'a0 t * 'a1 t * 'a2 t * 'a3 t * 'a4 t -> ('a0 * 'a1 * 'a2 * 'a3 * 'a4 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
external all6 : 'a0 t * 'a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t -> ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]

external race : 'a t array -> 'a t = "race" [@@bs.val] [@@bs.scope "Promise"]

external then_ : 'a t -> ('a -> 'b t [@bs.uncurry]) -> 'b t = "then" [@@bs.send]



external catch : 'a t -> (error -> 'a t [@bs.uncurry]) -> 'a t = "catch" [@@bs.send]
(* [ p |. catch handler]
Note in JS the returned promise type is actually runtime dependent,
if promise is rejected, it will pick the [handler] otherwise the original promise,
to make it strict we enforce reject handler
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
*)


(*
let errorAsExn (x : error) (e : (exn ->'a option))=
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
e (Obj.magic x)
else None
[%bs.error? ]
*)
5 changes: 3 additions & 2 deletions jscomp/others/release.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ build others/js_null_undefined.cmi : cc others/js_null_undefined.mli | runtime
build others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.ml | runtime
build others/js_option.cmj : cc others/js_option.ml | others/js_exn.cmj others/js_option.cmi runtime
build others/js_option.cmi : cc others/js_option.mli | runtime
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | runtime
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | others/js_promise2.cmj runtime
build others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.ml | runtime
build others/js_re.cmi : cc others/js_re.mli | others/js_re2.cmi runtime
build others/js_re2.cmi : cc others/js_re2.mli | runtime
build others/js_result.cmj : cc others/js_result.ml | others/js_result.cmi runtime
Expand All @@ -51,7 +52,7 @@ build others/js_undefined.cmj : cc others/js_undefined.ml | others/js_exn.cmj ot
build others/js_undefined.cmi : cc others/js_undefined.mli | runtime
build others/js_vector.cmj : cc others/js_vector.ml | others/js_vector.cmi runtime
build others/js_vector.cmi : cc others/js_vector.mli | runtime
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
build others/belt_Array.cmj : cc others/belt_Array.ml | others/belt.cmi others/belt_Array.cmi others/js_math.cmj js_pkg runtime
build others/belt_Array.cmi : cc others/belt_Array.mli | runtime
build others/belt_Debug.cmi others/belt_Debug.cmj : cc others/belt_Debug.ml | runtime
Expand Down
3 changes: 3 additions & 0 deletions jscomp/runtime/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ module Re2 = Js_re2
module Promise = Js_promise
(** Provide bindings to JS promise *)

module Promise2 = Js_promise2
(** Provide bindings to JS promise *)

module Date = Js_date
(** Provide bindings for JS Date *)

Expand Down
97 changes: 97 additions & 0 deletions jscomp/test/js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use strict';


var Internal = /* module */[];

var MapperRt = 0;

var Null = 0;

var Undefined = 0;

var Nullable = 0;

var Null_undefined = 0;

var Exn = 0;

var $$Array = 0;

var Array2 = 0;

var $$String = 0;

var String2 = 0;

var Re = 0;

var Re2 = 0;

var $$Promise = 0;

var Promise2 = 0;

var $$Date = 0;

var Dict = 0;

var Global = 0;

var Json = 0;

var $$Math = 0;

var Obj = 0;

var Typed_array = 0;

var TypedArray2 = 0;

var Types = 0;

var Float = 0;

var Int = 0;

var $$Option = 0;

var Result = 0;

var List = 0;

var Vector = 0;

var Console = 0;

exports.MapperRt = MapperRt;
exports.Internal = Internal;
exports.Null = Null;
exports.Undefined = Undefined;
exports.Nullable = Nullable;
exports.Null_undefined = Null_undefined;
exports.Exn = Exn;
exports.$$Array = $$Array;
exports.Array2 = Array2;
exports.$$String = $$String;
exports.String2 = String2;
exports.Re = Re;
exports.Re2 = Re2;
exports.$$Promise = $$Promise;
exports.Promise2 = Promise2;
exports.$$Date = $$Date;
exports.Dict = Dict;
exports.Global = Global;
exports.Json = Json;
exports.$$Math = $$Math;
exports.Obj = Obj;
exports.Typed_array = Typed_array;
exports.TypedArray2 = TypedArray2;
exports.Types = Types;
exports.Float = Float;
exports.Int = Int;
exports.$$Option = $$Option;
exports.Result = Result;
exports.List = List;
exports.Vector = Vector;
exports.Console = Console;
/* No side effect */
2 changes: 1 addition & 1 deletion jscomp/test/js_promise_basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Mt.from_pair_suites("Js_promise_basic_test", suites[0]);
var twop = Promise.resolve(2);

function then_(prim, prim$1) {
return prim$1.then(Curry.__1(prim));
return prim.then(Curry.__1(prim$1));
}

function re(prim) {
Expand Down
Loading