2
2
3
3
# Promise   ;  ;  ; [ ![ NPM link] [ npm-img ]] [ npm ] [ ![ Travis status] [ travis-img ]] [ travis ] [ ![ Coverage] [ coveralls-img ]] [ coveralls ]
4
4
5
- [ npm ] : https://www.npmjs.com/package/reason -promise
6
- [ npm-img ] : https://img.shields.io/npm/v/reason -promise
5
+ [ npm ] : https://www.npmjs.com/package/@dck/rescript -promise
6
+ [ npm-img ] : https://img.shields.io/npm/v/@dck/rescript -promise
7
7
[ travis ] : https://travis-ci.org/aantron/promise/branches
8
8
[ travis-img ] : https://img.shields.io/travis/aantron/promise/master.svg?label=travis
9
9
[ coveralls ] : https://coveralls.io/github/aantron/promise?branch=master
@@ -22,18 +22,18 @@ Promise.resolved("Hello")
22
22
As you can see on the first line, ` Promise.t ` maps directly to familiar JS
23
23
promises from your JS runtime. That means...
24
24
25
- - You can use ` reason -promise` directly to [ write JS bindings] ( #Bindings ) .
26
- - All JS tooling for promises immediately works with ` reason -promise` .
25
+ - You can use ` @dck/rescript -promise` directly to [ write JS bindings] ( #Bindings ) .
26
+ - All JS tooling for promises immediately works with ` @dck/rescript -promise` .
27
27
- Even if you do something exotic, like switch out the promise implementation at
28
- the JS level, for, say, better stack traces, ` reason -promise` still binds to
28
+ the JS level, for, say, better stack traces, ` @dck/rescript -promise` still binds to
29
29
it!
30
30
31
31
<br />
32
32
33
33
There is only one exception to the rule that ` Promise.t ` maps directly to JS
34
34
promises: when there is a promise nested inside another promise. JS [ breaks the
35
35
type safety] ( #JSPromiseFlattening ) of promises in a misguided attempt to
36
- disallow nesting. [ ` reason -promise` instead emulates it in a way that makes
36
+ disallow nesting. [ ` @dck/rescript -promise` instead emulates it in a way that makes
37
37
promises type-safe again] ( #TypeSafety ) . This is in contrast to BuckleScript's
38
38
built-in ` Js.Promise ` , which directly exposes the JS behavior, and so is not
39
39
type-safe.
@@ -42,10 +42,10 @@ type-safe.
42
42
43
43
In addition:
44
44
45
- - ` reason -promise` offers a clean functional API, which replaces rejection with
45
+ - ` rescript -promise` offers a clean functional API, which replaces rejection with
46
46
[ helpers for ` Result ` and ` Option ` ] ( #Errors ) .
47
- - ` reason -promise` is tiny. It weighs in at about [ 1K bundled] [ bundle-size ] .
48
- - ` reason -promise` also has a full, standalone [ pure-OCaml
47
+ - ` rescript -promise` is tiny. It weighs in at about [ 1K bundled] [ bundle-size ] .
48
+ - ` rescript -promise` also has a full, standalone [ pure-OCaml
49
49
implementation] [ native ] , which passes all the same tests. It can be used for
50
50
native code or in JS.
51
51
@@ -67,7 +67,7 @@ In addition:
67
67
- [ ** Advanced: Rejection** ] ( #Rejection )
68
68
- [ ** Advanced: Bindings** ] ( #Bindings )
69
69
- [ ** Discussion: Why JS promises are unsafe** ] ( #JSPromiseFlattening )
70
- - [ ** Discussion: How ` reason -promise` makes promises type-safe** ] ( #TypeSafety )
70
+ - [ ** Discussion: How ` rescript -promise` makes promises type-safe** ] ( #TypeSafety )
71
71
72
72
<br />
73
73
@@ -76,14 +76,14 @@ In addition:
76
76
### Installing
77
77
78
78
```
79
- npm install reason -promise
79
+ npm install @dck/rescript -promise
80
80
```
81
81
82
- Then, add ` reason -promise` to your ` bsconfig .json` :
82
+ Then, add ` @dck/rescript -promise` to your ` rescript .json` :
83
83
84
84
``` json
85
85
{
86
- "bs-dependencies" : [" reason -promise" ]
86
+ "bs-dependencies" : [" @dck/rescript -promise" ]
87
87
}
88
88
```
89
89
@@ -581,7 +581,7 @@ directly, safely be used from ReScript.
581
581
582
582
<a id =" TypeSafety " ></a >
583
583
584
- ### Discussion: How ` reason -promise` makes promises type-safe
584
+ ### Discussion: How ` @dck/rescript -promise` makes promises type-safe
585
585
586
586
The [ previous section] ( #JSPromiseFlattening ) shows that JS promise functions are
587
587
broken. An important observation is that it is only the _ functions_ that are
@@ -591,14 +591,14 @@ safe replacement functions to use with it in ReScript. This is good news
591
591
for interop :)
592
592
593
593
To fix the functions, only the [ special-case flattening] ( #JSPromiseFlattening )
594
- has to be undone. So, when you call ` reason -promise` 's
594
+ has to be undone. So, when you call ` @dck/rescript -promise` 's
595
595
[ ` Promise.resolved(value) ` ] [ resolved ] , it checks whether ` value ` is a promise
596
596
or not, and...
597
597
598
- - If ` value ` _ is not_ a promise, ` reason -promise` just passes it to JS's
598
+ - If ` value ` _ is not_ a promise, ` @dck/rescript -promise` just passes it to JS's
599
599
[ ` Promise.resolve ` ] [ Promise.resolve ] , because JS will do the right thing.
600
600
- If ` value ` _ is_ a promise, it's not safe to simply pass it to JS, because it
601
- will trigger the special-casing. So, ` reason -promise` boxes the nested
601
+ will trigger the special-casing. So, ` @dck/rescript -promise` boxes the nested
602
602
promise:
603
603
604
604
``` rescript
@@ -612,17 +612,17 @@ or not, and...
612
612
enough to suppress the special-casing.
613
613
614
614
Whenever you try to take the value out of this resulting structure (for
615
- example, by calling [ ` Promise.get ` ] [ get ] on it), ` reason -promise`
615
+ example, by calling [ ` Promise.get ` ] [ get ] on it), ` @dck/rescript -promise`
616
616
transparently unboxes the ` PromiseBox ` and passes the nested promise to your
617
617
callback &mdash ; as your callback would expect.
618
618
619
- This conditional boxing and unboxing is done throughout ` reason -promise` . It
619
+ This conditional boxing and unboxing is done throughout ` @dck/rescript -promise` . It
620
620
only happens for nested promises, and anything else with a ` .then ` method. For
621
- all other values, ` reason -promise` behaves, internally, exactly like JS
621
+ all other values, ` @dck/rescript -promise` behaves, internally, exactly like JS
622
622
` Promise ` (though with a cleaner outer API). This is enough to make promises
623
623
type-safe.
624
624
625
- This is a simple scheme, but ` reason -promise` includes a very thorough
625
+ This is a simple scheme, but ` @dck/rescript -promise` includes a very thorough
626
626
[ test suite] [ tests ] to be extra sure that it always manages the boxing
627
627
correctly.
628
628
0 commit comments