Comparing version 4.1.1 to 4.2.0
@@ -45,3 +45,2 @@ //// ____ _ _ | ||
function isForkable(m){ | ||
deprecate('Future.isForkable() is deprecated.'); | ||
return Boolean(m) && typeof m.fork === 'function' && m.fork.length >= 2; | ||
@@ -321,2 +320,3 @@ } | ||
Future.isFuture = isFuture; | ||
Future.isForkable = isForkable; | ||
@@ -422,4 +422,4 @@ function ap$mval(mval, mfunc){ | ||
Future.cast = function Future$cast(m){ | ||
deprecate('Future.cast() is deprecated. Please use Future((l, r) => {m.fork(l, r)})'); | ||
return new SafeFuture((l, r) => void m.fork(l, r)); | ||
deprecate('Future.cast has been renamed to Future.fromForkable and will soon be removed'); | ||
return Future.fromForkable(m); | ||
}; | ||
@@ -461,2 +461,7 @@ | ||
Future.fromForkable = function Future$fromForkable(f){ | ||
if(!isForkable(f)) error$invalidArgument('Future.fromForkable', 0, 'be a forkable', f); | ||
return new FutureFromForkable(f); | ||
} | ||
Future.fromPromise = function Future$fromPromise(f, x){ | ||
@@ -994,2 +999,29 @@ if(arguments.length === 1) return unaryPartial(Future$fromPromise, f); | ||
function FutureFromForkable(forkable){ | ||
this._forkable = forkable; | ||
} | ||
FutureFromForkable.prototype = Object.create(Future.prototype); | ||
FutureFromForkable.prototype._f = function FutureFromForkable$fork(rej, res){ | ||
let pending = true; | ||
return this._forkable.fork(function FutureFromForkable$fork$rej(reason){ | ||
if(pending){ | ||
pending = false; | ||
rej(reason); | ||
} | ||
}, function FutureFromForkable$res(value){ | ||
if(pending){ | ||
pending = false; | ||
res(value); | ||
} | ||
}); | ||
} | ||
FutureFromForkable.prototype.toString = function FutureFromForkable$toString(){ | ||
return `Future.fromForkable(${show(this._forkable)})`; | ||
} | ||
//---------- | ||
function FutureTry(fn){ | ||
@@ -1498,2 +1530,3 @@ this._fn = fn; | ||
FutureEncase, | ||
FutureFromForkable, | ||
FutureFromPromise, | ||
@@ -1500,0 +1533,0 @@ FutureChain, |
{ | ||
"name": "fluture", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "FantasyLand compliant (monadic) alternative to Promises", | ||
@@ -5,0 +5,0 @@ "main": "fluture.js", |
@@ -64,2 +64,3 @@ # Fluture | ||
* [encase](#encase) | ||
* [fromForkable](#fromForkable) | ||
* [fromPromise](#frompromise) | ||
@@ -93,2 +94,3 @@ * [node](#node) | ||
* [isFuture](#isfuture) | ||
* [isForkable](#isforkable) | ||
* [cache](#cache) | ||
@@ -119,2 +121,5 @@ * [do](#do) | ||
- **Forkable** - Any Object with a `fork` method that takes at least two | ||
arguments. This includes instances of Fluture, instances of Task from | ||
[`data.task`][10] or instances of Future from [`ramda-fantasy`][11]. | ||
- **Future** - Instances of Future provided by Fluture. | ||
@@ -139,3 +144,3 @@ - **Promise** - Values which conform to the [Promises/A+ specification][33]. | ||
#### Future | ||
##### `Future :: ((a -> ()), (b -> ()) -> Cancel) -> Future a b` | ||
##### `Future :: ((a -> (), b -> ()) -> Cancel) -> Future a b` | ||
@@ -249,2 +254,12 @@ Creates a Future with the given computation. A computation is a function which | ||
#### fromForkable | ||
##### `.fromForkable :: Forkable a b -> Future a b` | ||
Cast any [Forkable](#type-signatures) to a [Future](#type-signatures). | ||
```js | ||
Future.fromForkable(require('data.task').of('hello')).value(console.log); | ||
//> "hello" | ||
``` | ||
#### fromPromise | ||
@@ -275,3 +290,3 @@ ##### `.fromPromise :: (a -> Promise e r) -> a -> Future e r` | ||
#### node | ||
##### `.node :: ((a, b -> ()) -> ()) -> Future a b` | ||
##### `.node :: (((a, b) -> ()) -> ()) -> Future a b` | ||
@@ -440,3 +455,3 @@ Creates a Future which rejects with the first argument given to the function, | ||
#### fold | ||
##### `#fold :: Future a b ~> (a -> c), (b -> c) -> Future _ c` | ||
##### `#fold :: Future a b ~> (a -> c, b -> c) -> Future _ c` | ||
##### `.fold :: (a -> c) -> (b -> c) -> Future a b -> Future _ c` | ||
@@ -551,3 +566,3 @@ | ||
#### fork | ||
##### `#fork :: Future a b ~> (a -> ()), (b -> ()) -> Cancel` | ||
##### `#fork :: Future a b ~> (a -> (), b -> ()) -> Cancel` | ||
##### `.fork :: (a -> ()) -> (b -> ()) -> Future a b -> Cancel` | ||
@@ -776,2 +791,7 @@ | ||
#### isForkable | ||
##### `.isForkable :: a -> Boolean` | ||
Returns true for [Forkables](#type-signatures) and false for everything else. | ||
#### cache | ||
@@ -778,0 +798,0 @@ ##### `.cache :: Future a b -> Future a b` |
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
83252
1284
961