|
| 1 | +/* Copyright (C) 2015-2016 Bloomberg Finance L.P. |
| 2 | + * |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU Lesser General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * |
| 8 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 9 | + * or link a "work that uses the Library" with a publicly distributed version |
| 10 | + * of this file to produce a combined library or application, then distribute |
| 11 | + * that combined work under the terms of your choosing, with no requirement |
| 12 | + * to comply with the obligations normally placed on you by section 4 of the |
| 13 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 14 | + * should you choose to use a later version). |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Lesser General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Lesser General Public License |
| 22 | + * along with this program; if not, write to the Free Software |
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 24 | + |
| 25 | +/*** |
| 26 | +Deprecation note: These bindings are pretty outdated and cannot be used properly |
| 27 | +with the `->` operator. |
| 28 | +
|
| 29 | +More details on proper Promise usage can be found here: |
| 30 | +https://rescript-lang.org/docs/manual/latest/promise#promise-legacy |
| 31 | +*/ |
| 32 | + |
| 33 | +@@warning("-103") |
| 34 | + |
| 35 | +@deprecated({ |
| 36 | + reason: "Use `promise` directly instead.", |
| 37 | + migrate: %replace.type(: promise), |
| 38 | +}) |
| 39 | +type t<+'a> = promise<'a> |
| 40 | + |
| 41 | +@deprecated({ |
| 42 | + reason: "Use `exn` directly instead.", |
| 43 | + migrate: %replace.type(: exn), |
| 44 | +}) |
| 45 | +type error = Js_promise2.error |
| 46 | + |
| 47 | +/* |
| 48 | +## Examples |
| 49 | +
|
| 50 | +```rescript |
| 51 | +type error |
| 52 | +``` |
| 53 | +*/ |
| 54 | + |
| 55 | +@deprecated({ |
| 56 | + reason: "Use `Promise.make` instead.", |
| 57 | + migrate: Promise.make( |
| 58 | + @apply.transforms(["labelledToUnlabelledArgumentsInFnDefinition"]) |
| 59 | + %insert.unlabelledArgument(0), |
| 60 | + ), |
| 61 | +}) |
| 62 | +@new |
| 63 | +external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise" |
| 64 | + |
| 65 | +/* `make (fun resolve reject -> .. )` */ |
| 66 | +@deprecated({ |
| 67 | + reason: "Use `Promise.resolve` instead.", |
| 68 | + migrate: Promise.resolve(), |
| 69 | +}) |
| 70 | +@val |
| 71 | +@scope("Promise") |
| 72 | +external resolve: 'a => promise<'a> = "resolve" |
| 73 | +@deprecated({ |
| 74 | + reason: "Use `Promise.reject` instead.", |
| 75 | + migrate: Promise.reject(), |
| 76 | +}) |
| 77 | +@val |
| 78 | +@scope("Promise") |
| 79 | +external reject: exn => promise<'a> = "reject" |
| 80 | + |
| 81 | +@deprecated({ |
| 82 | + reason: "Use `Promise.all` instead.", |
| 83 | + migrate: Promise.all(), |
| 84 | +}) |
| 85 | +@val |
| 86 | +@scope("Promise") |
| 87 | +external all: array<promise<'a>> => promise<array<'a>> = "all" |
| 88 | + |
| 89 | +@deprecated({ |
| 90 | + reason: "Use `Promise.all2` instead.", |
| 91 | + migrate: Promise.all2(), |
| 92 | +}) |
| 93 | +@val |
| 94 | +@scope("Promise") |
| 95 | +external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" |
| 96 | + |
| 97 | +@deprecated({ |
| 98 | + reason: "Use `Promise.all3` instead.", |
| 99 | + migrate: Promise.all3(), |
| 100 | +}) |
| 101 | +@val |
| 102 | +@scope("Promise") |
| 103 | +external all3: ((promise<'a0>, promise<'a1>, promise<'a2>)) => promise<('a0, 'a1, 'a2)> = "all" |
| 104 | + |
| 105 | +@deprecated({ |
| 106 | + reason: "Use `Promise.all4` instead.", |
| 107 | + migrate: Promise.all4(), |
| 108 | +}) |
| 109 | +@val |
| 110 | +@scope("Promise") |
| 111 | +external all4: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>)) => promise<( |
| 112 | + 'a0, |
| 113 | + 'a1, |
| 114 | + 'a2, |
| 115 | + 'a3, |
| 116 | +)> = "all" |
| 117 | + |
| 118 | +@deprecated({ |
| 119 | + reason: "Use `Promise.all5` instead.", |
| 120 | + migrate: Promise.all5(), |
| 121 | +}) |
| 122 | +@val |
| 123 | +@scope("Promise") |
| 124 | +external all5: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>)) => promise<( |
| 125 | + 'a0, |
| 126 | + 'a1, |
| 127 | + 'a2, |
| 128 | + 'a3, |
| 129 | + 'a4, |
| 130 | +)> = "all" |
| 131 | + |
| 132 | +@deprecated({ |
| 133 | + reason: "Use `Promise.all6` instead.", |
| 134 | + migrate: Promise.all6(), |
| 135 | +}) |
| 136 | +@val |
| 137 | +@scope("Promise") |
| 138 | +external all6: ( |
| 139 | + (promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>, promise<'a5>) |
| 140 | +) => promise<('a0, 'a1, 'a2, 'a3, 'a4, 'a5)> = "all" |
| 141 | + |
| 142 | +@deprecated({ |
| 143 | + reason: "Use `Promise.race` instead.", |
| 144 | + migrate: Promise.race(), |
| 145 | +}) |
| 146 | +@val |
| 147 | +@scope("Promise") |
| 148 | +external race: array<promise<'a>> => promise<'a> = "race" |
| 149 | + |
| 150 | +@deprecated({ |
| 151 | + reason: "Use `Promise.then` instead.", |
| 152 | + migrate: Promise.then(), |
| 153 | +}) |
| 154 | + |
| 155 | +@deprecated({ |
| 156 | + reason: "Use `Promise.then` instead.", |
| 157 | + migrate: Promise.then(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), |
| 158 | + migrateInPipeChain: Promise.then(%insert.unlabelledArgument(0)), |
| 159 | +}) |
| 160 | +let then_: ('a => promise<'b>, promise<'a>) => promise<'b> |
| 161 | + |
| 162 | +@deprecated({ |
| 163 | + reason: "Use `Promise.catch` instead.", |
| 164 | + migrate: Promise.catch(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), |
| 165 | + migrateInPipeChain: Promise.catch(%insert.unlabelledArgument(0)), |
| 166 | +}) |
| 167 | +let catch: (error => promise<'a>, promise<'a>) => promise<'a> |
| 168 | +/* ` p|> catch handler` |
| 169 | + Note in JS the returned promise type is actually runtime dependent, |
| 170 | + if promise is rejected, it will pick the `handler` otherwise the original promise, |
| 171 | + to make it strict we enforce reject handler |
| 172 | + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch |
| 173 | +*/ |
| 174 | + |
| 175 | +/* |
| 176 | +let errorAsExn (x : error) (e : (exn ->'a option))= |
| 177 | + if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then |
| 178 | + e (Obj.magic x) |
| 179 | + else None |
| 180 | +[%bs.error? ] |
| 181 | +*/ |
0 commit comments