Skip to content

Commit b0e40ee

Browse files
Merge pull request #57 from nicktytarenko/bs-platform-to-rescript
Upgrade `reason-future` to Support ReScript 11+
2 parents 9559b90 + 23fe38a commit b0e40ee

20 files changed

+3644
-936
lines changed

.vscode/tasks.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.0",
2+
"version": "2.0.0",
33
"command": "npm",
44
"options": {
55
"cwd": "${workspaceRoot}"
@@ -38,5 +38,45 @@
3838
"loop": true
3939
}
4040
]
41-
}
41+
},
42+
"tasks": [
43+
{
44+
"label": "npm",
45+
"type": "shell",
46+
"command": "npm",
47+
"args": [
48+
"run",
49+
"start"
50+
],
51+
"isBackground": true,
52+
"problemMatcher": {
53+
"fileLocation": "absolute",
54+
"owner": "ocaml",
55+
"background": {
56+
"activeOnStart": false,
57+
"beginsPattern": ">>>> Start compiling",
58+
"endsPattern": ">>>> Finish compiling"
59+
},
60+
"pattern": [
61+
{
62+
"regexp": "^File \"(.*)\", line (\\d+)(?:, characters (\\d+)-(\\d+))?:$",
63+
"file": 1,
64+
"line": 2,
65+
"column": 3,
66+
"endColumn": 4
67+
},
68+
{
69+
"regexp": "^(?:(?:Parse\\s+)?(Warning|[Ee]rror)(?:\\s+\\d+)?:)?\\s+(.*)$",
70+
"severity": 1,
71+
"message": 2,
72+
"loop": true
73+
}
74+
]
75+
},
76+
"group": {
77+
"_id": "build",
78+
"isDefault": false
79+
}
80+
}
81+
]
4282
}

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44

55
# The Future is Now
66

7-
Future is a `Js.Promise` alternative. It is written in ReasonML.
7+
Future is a lightweight, functional alternative to `Js.Promise` for ReScript, designed to make async code more composable and maintainable.
88

9-
Compared to a promise, a future is:
9+
### Compatibility
10+
- Use `[email protected]` for ReasonML or ReScript ≤ v10.
11+
- Use `[email protected]` for ReScript ≥ v11.
12+
13+
14+
### Key Benefits of Using Future Over Promises:
1015

1116
- **Lighter weight** – Only ~25 lines of implementation.
1217
- **Simpler** – Futures only resolve to a single type (as opposed to resolve and reject types), giving you more flexibility on your error handling.
1318
- **More robust** – Futures have sound typing (unlike JS promises).
1419

1520
## Installation
1621

17-
First make sure you have bs-platform `>= 3.1.0`. Then install with npm:
22+
First make sure you have rescript `>= 11.1.X`. Then install with npm:
1823

1924
```
2025
$ npm install --save reason-future
2126
```
2227

23-
Then add `"reason-future"` to your `bsconfig.json` dev dependencies:
28+
Then add `"reason-future"` to your `rescript.json` dev dependencies:
2429

2530
```
2631
{
@@ -33,7 +38,7 @@ Then add `"reason-future"` to your `bsconfig.json` dev dependencies:
3338

3439
## Basic Usage
3540

36-
To create a task, use `Future.make`. It provides a single `resolve` function, like a promise with no `reject`:
41+
To create a task, use `Future.make`. It provides a single `resolve` function, similar to how Promises work but without a `reject`:
3742

3843
```js
3944
let futureGreeting = Future.make(resolve => resolve("hi"));
@@ -79,7 +84,7 @@ let ft_b = futureNum->Future.flatMap(n => Future.value(n + 20));
7984

8085
## API
8186

82-
Core functions. **Note:** `_` represents the future itself as inserted by `->` (the [fast pipe](https://bucklescript.github.io/docs/en/fast-pipe.html) operator).
87+
Core functions. **Note:** `_` represents the future itself as inserted by `->` (the [pipe](https://rescript-lang.org/docs/manual/latest/pipe) operator).
8388

8489
- `Future.make(resolver)` - Create a new, potentially-async future.
8590
- `Future.value(x)` - Create a new future with a plain value (synchronous).
@@ -89,15 +94,15 @@ Core functions. **Note:** `_` represents the future itself as inserted by `->` (
8994
- `Future.tap(_,fn)` - Do something with the value of a future without changing it. Returns the same future so you can continue using it in a pipeline. Convenient for side effects such as console logging.
9095
- `Future.all(_,fn)` - Turn a list of futures into a future of a list. Used when you want to wait for a collection of futures to complete before doing something (equivalent to Promise.all in Javascript).
9196

92-
### Belt.Result
97+
### Result
9398

94-
Convenience functions when working with a future `Belt.Result`. **Note:** `_` represents the future itself as inserted by `->` (the [fast pipe](https://bucklescript.github.io/docs/en/fast-pipe.html) operator).
99+
Convenience functions when working with a future `Result`. **Note:** `_` represents the future itself as inserted by `->` (the [pipe](https://rescript-lang.org/docs/manual/latest/pipe) operator).
95100

96-
**Note 2**: The terms `Result.Ok` and `Result.Error` in this context are expected to be read as `Belt.Result.Ok` and `Belt.Result.Error`.
101+
**Note 2**: The terms `Result.Ok` and `Result.Error` in this context are expected to be read as `Ok` and `Error`.
97102

98103
- `Future.mapOk(_,fn)` - Transform a future value into another value, but only if the value is an `Result.Ok`. Similar to `Promise.prototype.then`
99104
- `Future.mapError(_,fn)` - Transform a future value into another value, but only if the value is an `Result.Error`. Similar to `Promise.prototype.catch`
100-
- `Future.tapOk(_,fn)` - Do something with the value of a future without changing it, but only if the value is a `Belt.Result.Ok`. Returns the same future. Convenience for side effects such as console logging.
105+
- `Future.tapOk(_,fn)` - Do something with the value of a future without changing it, but only if the value is a `Ok`. Returns the same future. Convenience for side effects such as console logging.
101106
- `Future.tapError(_,fn)` - Same as `tapOk` but for `Result.Error`
102107

103108
The following are more situational:
@@ -112,18 +117,18 @@ a future `Result`. Flattens the inner future.
112117
Convenience functions for interop with JavaScript land.
113118

114119
- `FutureJs.fromPromise(promise, errorTransformer)`
115-
- `promise` is the `Js.Promise.t('a)` that will be transformed into a
116-
`Future.t(Belt.Result.t('a, 'e))`
117-
- `errorTransformer` allows you to determine how `Js.Promise.error`
120+
- `promise` is the `RescriptCore.Promise.t('a)` that will be transformed into a
121+
`Future.t(result('a, 'e))`
122+
- `errorTransformer` allows you to determine how `Promise.error`
118123
objects will be transformed before they are returned wrapped within
119-
a `Belt.Result.Error`. This allows you to implement the error handling
124+
a `Error`. This allows you to implement the error handling
120125
method which best meets your application's needs.
121126
- `FutureJs.toPromise(future)`
122127
- `future` is any `Future.t('a)` which is transformed into a
123-
`Js.Promise.t('a)`. Always resolves, never rejects the promise.
128+
`RescriptCore.Promise.t('a)`. Always resolves, never rejects the promise.
124129
- `FutureJs.resultToPromise(future)`
125-
- `future` is the `Future.t(Belt.Result('a, 'e))` which is transformed into a
126-
`Js.Promise.t('a)`. Resolves the promise on Ok result and rejects on Error result.
130+
- `future` is the `Future.t(result('a, 'e))` which is transformed into a
131+
`RescriptCore.Promise.t('a)`. Resolves the promise on Ok result and rejects on Error result.
127132

128133
Example use:
129134

0 commit comments

Comments
 (0)