Comparing version 0.6.0-beta1 to 0.6.0-beta2
@@ -557,3 +557,9 @@ /*global define FantasyLand inspectf*/ | ||
return new FutureClass(function Future$cast$fork(rej, res){ | ||
m.fork(rej, res); | ||
let cleared = false; | ||
m.fork(function Future$cast$rej(x){ | ||
cleared || rej(x); | ||
}, function Future$cast$res(x){ | ||
cleared || res(x); | ||
}); | ||
return () => (cleared = true); | ||
}); | ||
@@ -584,3 +590,5 @@ }; | ||
return new FutureClass(function Future$node$fork(rej, res){ | ||
f((a, b) => a ? rej(a) : res(b)); | ||
let cleared = false; | ||
f((a, b) => cleared || (a ? rej(a) : res(b))); | ||
return () => (cleared = true); | ||
}); | ||
@@ -587,0 +595,0 @@ }; |
{ | ||
"name": "fluture", | ||
"version": "0.6.0-beta1", | ||
"version": "0.6.0-beta2", | ||
"description": "A mathematically correct alternative to Promises for asynchronous control flow", | ||
@@ -5,0 +5,0 @@ "main": "fluture.js", |
@@ -24,3 +24,3 @@ # Fluture | ||
- [Type signatures](#type-signatures) | ||
- [Constructors](#constructors) | ||
- [Creation](#creation) | ||
- [Method API](#method-api) | ||
@@ -96,13 +96,21 @@ - [Dispatcher API](#dispatcher-api) | ||
### Constructors | ||
### Creation | ||
#### `Future :: ((a -> ()), (b -> ()) -> ?(() -> ())) -> Future a b` | ||
#### `Future :: ((a -> ()), (b -> ()) -> ?(() -> ())) -> ?Bool -> Future a b` | ||
A (monadic) container which represents an eventual value. A lot like Promise but | ||
more principled in that it follows the [Fantasy Land][1] algebraic JavaScript | ||
specification. | ||
The Future constructor. Creates a new instance of Future. Takes two parameters: | ||
* `fork`: A function which takes two callbacks. Both are continuations for an | ||
asynchronous computation. The first is `reject`, commonly abreviated to `rej`. | ||
The second `resolve`, which abreviates to `res`. The `fork` function is | ||
expected to call `rej` once an error occurs, or `res` with the result of the | ||
asynchronous computation. Additionally, another function *may* be returned to | ||
be used for [cancellation or resource disposal](#cancellation-and-resource-disposal). | ||
* `autoclear`: Whether to [automatically dispose of resources](#automatic-resource-disposal) | ||
when a resource disposal function is returned from `fork`. Defaults to true. | ||
It's quite likely you'll never need to override this. | ||
```js | ||
const eventualThing = Future((reject, resolve) => { | ||
setTimeout(resolve, 500, 'world'); | ||
const eventualThing = Future((rej, res) => { | ||
setTimeout(res, 500, 'world'); | ||
}); | ||
@@ -117,5 +125,7 @@ | ||
#### `of :: b -> Future a b` | ||
#### `of :: a -> Future _ a` | ||
A constructor that creates a Future containing the given value. | ||
Creates a Future which immediately resolves with the given value. This function | ||
is compliant with the [Fantasy Land Applicative specification][16] and is | ||
also available on the prototype. | ||
@@ -131,5 +141,10 @@ ```js | ||
#### `reject :: a -> Future a _` | ||
Creates a Future which immediately rejects with the given value. Just like `of` | ||
but for the rejection branch. | ||
#### `after :: Number -> b -> Future a b` | ||
A constructor that creates a Future containing the given value after n milliseconds. | ||
Creates a Future which resolves with the given value after n milliseconds. | ||
@@ -165,4 +180,4 @@ ```js | ||
A constructor that creates a Future which resolves with the result of calling | ||
the given function, or rejects with the error thrown by the given function. | ||
Creates a Future which resolves with the result of calling the given function, | ||
or rejects with the error thrown by the given function. | ||
@@ -180,7 +195,8 @@ Sugar for `Future.encase(f, undefined)`. | ||
A constructor that creates a Future which rejects with the first argument given | ||
to the function, or resolves with the second if the first is not present. | ||
Creates a Future which rejects with the first argument given to the function, | ||
or resolves with the second if the first is not present. | ||
This is a convenience for NodeJS users who wish to easily obtain a Future from | ||
a node style callback API. | ||
a node style callback API. To permanently turn a function into one that returns | ||
a Future, check out [futurization](#futurization). | ||
@@ -241,8 +257,7 @@ ```js | ||
Execute the Future (which up until now was merely a container for its | ||
computation), and get at the result or error. | ||
Execute the Future by calling the `fork` function that was passed to it at | ||
[construction](#creation) with the `reject` and `resolve` callbacks. Futures are | ||
*lazy*, which means even if you've `map`ped or `chain`ed over them, they'll do | ||
*nothing* if you don't eventually fork them. | ||
It is the return from Fantasy Land to the real world. This function best shows | ||
the fundamental difference between Promises and Futures. | ||
```js | ||
@@ -264,4 +279,8 @@ Future.of('world').fork( | ||
Map over the value inside the Future. If the Future is rejected, mapping is not | ||
performed. | ||
Transforms the resolution value inside the Future, and returns a new Future with | ||
the transformed value. This is like doing `promise.then(x => x + 1)`, except | ||
that it's lazy, so the transformation will not be applied before the Future is | ||
forked. The transformation is only applied to the resolution branch. So if the | ||
Future is rejected, the transformation is ignored. To learn more about the exact | ||
behaviour of `map`, check out its [spec][12]. | ||
@@ -277,4 +296,7 @@ ```js | ||
FlatMap over the value inside the Future. If the Future is rejected, chaining is | ||
not performed. | ||
Allows the creation of a new Future based on the resolution value. This is like | ||
doing `promise.then(x => Promise.resolve(x + 1))`, except that it's lazy, so the | ||
new Future will not be created until the other one is forked. The function is | ||
only ever applied to the resolution value, so is ignored when the Future was | ||
rejected. To learn more about the exact behaviour of `chain`, check out its [spec][13]. | ||
@@ -290,4 +312,4 @@ ```js | ||
FlatMap over the **rejection** value inside the Future. If the Future is | ||
resolved, chaining is not performed. | ||
Chain over the **rejection** reason of the Future. This is like `chain`, but for | ||
the rejection branch. | ||
@@ -305,4 +327,7 @@ ```js | ||
Apply the value in the Future to the value in the given Future. If the Future is | ||
rejected, applying is not performed. | ||
Apply the resolution value, which is expected to be a function (as in | ||
`Future.of(a_function)`), to the resolution value in the given Future. Both | ||
Futures involved will run in parallel, and if one rejects the resulting Future | ||
will also be rejected. To learn more about the exact behaviour of `ap`, check | ||
out its [spec][14]. | ||
@@ -523,4 +548,4 @@ ```js | ||
It's the responsibility of this `fork` function to prevent `rej` or `res` from | ||
being called after its returned disposal function has been called. All internal | ||
Fluture functions, for example `Future.after`, play by these rules. | ||
being called after its returned disposal function has been called. All of the | ||
functions in Fluture play by these rules. | ||
@@ -633,1 +658,2 @@ ```js | ||
[15]: https://github.com/Avaq/Fluture/wiki/Comparison-of-Future-Implementations | ||
[16]: https://github.com/fantasyland/fantasy-land#applicative |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42625
544
647