Skip to content

Commit

Permalink
Release 12.0.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Aug 21, 2019
1 parent 7940158 commit 88f9a9f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ getPackageName ('package.json')
### Global Bundle (CDN)

Fluture is hosted in full with all of its dependencies at
https://cdn.jsdelivr.net/gh/fluture-js/[email protected].2/dist/bundle.js
https://cdn.jsdelivr.net/gh/fluture-js/[email protected].3/dist/bundle.js

This script will add `Fluture` to the global scope.

Expand Down
92 changes: 63 additions & 29 deletions dist/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Fluture bundled; version 12.0.0-beta.2
* Fluture bundled; version 12.0.0-beta.3
*/

var Fluture = (function () {
Expand Down Expand Up @@ -217,7 +217,16 @@ var Fluture = (function () {

var $$type = namespace + '/' + name + '@' + version;

var nil = {head: null};
function List(head, tail){
this.head = head;
this.tail = tail;
}

List.prototype.toJSON = function(){
return toArray(this);
};

var nil = new List(null, null);
nil.tail = nil;

function isNil(list){
Expand All @@ -227,7 +236,7 @@ var Fluture = (function () {
// cons :: (a, List a) -> List a
// -- O(1) append operation
function cons(head, tail){
return {head: head, tail: tail};
return new List(head, tail);
}

// reverse :: List a -> List a
Expand All @@ -252,6 +261,17 @@ var Fluture = (function () {
return zs;
}

// toArray :: List a -> Array a
// -- O(n) list to Array
function toArray(xs){
var tail = xs, arr = [];
while(!isNil(tail)){
arr.push(tail.head);
tail = tail.tail;
}
return arr;
}

/* istanbul ignore next: non v8 compatibility */
var captureStackTrace = Error.captureStackTrace || captureStackTraceFallback;
var _debug = debugHandleNone;
Expand Down Expand Up @@ -677,6 +697,18 @@ var Fluture = (function () {
return true;
}

function getArgs(it){
var args = new Array(it.arity);
for(var i = 1; i <= it.arity; i++){
args[i - 1] = it['$' + String(i)];
}
return args;
}

function showArg$1(arg){
return ' (' + sanctuaryShow(arg) + ')';
}

var any = {pred: alwaysTrue, error: invalidArgumentOf('be anything')};
var func = {pred: isFunction, error: invalidArgumentOf('be a Function')};
var future = {pred: isFuture, error: invalidFutureArgument};
Expand Down Expand Up @@ -757,12 +789,12 @@ var Fluture = (function () {
Future.prototype.arity = 0;
Future.prototype.name = 'future';

Future.prototype.toString = function(){
var str = this.name;
for(var i = 1; i <= this.arity; i++){
str += ' (' + sanctuaryShow(this['$' + String(i)]) + ')';
}
return str;
Future.prototype.toString = function Future$toString(){
return this.name + getArgs(this).map(showArg$1).join('');
};

Future.prototype.toJSON = function Future$toJSON(){
return {$: $$type, kind: 'interpreter', type: this.name, args: getArgs(this)};
};

function createInterpreter(arity, name, interpret){
Expand Down Expand Up @@ -879,7 +911,8 @@ var Fluture = (function () {
}));
}

var Transformer = createInterpreter(2, '', function Transformer$interpret(rec, rej, res){
var Transformer =
createInterpreter(2, 'transform', function Transformer$interpret(rec, rej, res){

//These are the cold, and hot, transformation stacks. The cold actions are those that
//have yet to run parallel computations, and hot are those that have.
Expand All @@ -893,14 +926,14 @@ var Fluture = (function () {
// async = a boolean indicating whether we are awaiting a result asynchronously
var future, transformation, cancel = noop, settled, async = true, it;

//Takes an transformation from the top of the hot stack and returns it.
//Takes a transformation from the top of the hot stack and returns it.
function nextHot(){
var x = hot.head;
hot = hot.tail;
return x;
}

//Takes an transformation from the top of the cold stack and returns it.
//Takes a transformation from the top of the cold stack and returns it.
function nextCold(){
var x = cold.head;
cold = cold.tail;
Expand Down Expand Up @@ -1024,18 +1057,9 @@ var Fluture = (function () {
};

Transformer.prototype.toString = function Transformer$toString(){
var i, str = this.$1.toString(), str2, tail = this.$2;

while(!isNil(tail)){
str2 = tail.head.name;
for(i = 1; i <= tail.head.arity; i++){
str2 += ' (' + sanctuaryShow(tail.head['$' + String(i)]) + ')';
}
str = str2 + ' (' + str + ')';
tail = tail.tail;
}

return str;
return toArray(reverse(this.$2)).reduce(function(str, action){
return action.name + getArgs(action).map(showArg$1).join('') + ' (' + str + ')';
}, this.$1.toString());
};

function BaseTransformation$rejected(x){
Expand All @@ -1048,14 +1072,19 @@ var Fluture = (function () {
return new Resolve(this.context, x);
}

function BaseTransformation$toJSON(){
return {$: $$type, kind: 'transformation', type: this.name, args: getArgs(this)};
}

var BaseTransformation = {
rejected: BaseTransformation$rejected,
resolved: BaseTransformation$resolved,
run: moop,
cancel: noop,
context: nil,
arity: 0,
name: 'transform'
name: 'transform',
toJSON: BaseTransformation$toJSON
};

function wrapHandler(handler){
Expand Down Expand Up @@ -1695,8 +1724,8 @@ var Fluture = (function () {
if(!isFuture(disposal)){
return Hook$rec(invalidDisposal(disposal, _dispose, resource));
}
disposal._interpret(Hook$rec, Hook$disposalRejected, Hook$done);
cancel = Hook$cancelDisposal;
disposal._interpret(Hook$rec, Hook$disposalRejected, Hook$done);
}

function Hook$cancelConsumption(){
Expand Down Expand Up @@ -1879,23 +1908,28 @@ var Fluture = (function () {

var _this = this, futures = this.$2, length = futures.length;
var max = Math.min(this.$1, length), cancels = new Array(length), out = new Array(length);
var cursor = 0, running = 0, blocked = false;
var cursor = 0, running = 0, blocked = false, cont = noop;

function Parallel$cancel(){
rec = noop;
rej = noop;
res = noop;
cursor = length;
for(var n = 0; n < length; n++) cancels[n] && cancels[n]();
}

function Parallel$run(idx){
running++;
cancels[idx] = futures[idx]._interpret(function Parallel$rec(e){
cont = rec;
cancels[idx] = noop;
Parallel$cancel();
rec(wrapException(e, _this));
cont(wrapException(e, _this));
}, function Parallel$rej(reason){
cont = rej;
cancels[idx] = noop;
Parallel$cancel();
rej(reason);
cont(reason);
}, function Parallel$res(value){
cancels[idx] = noop;
out[idx] = value;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluture",
"version": "12.0.0-beta.2",
"version": "12.0.0-beta.3",
"description": "FantasyLand compliant (monadic) alternative to Promises",
"main": "index",
"types": "index.d.ts",
Expand Down

0 comments on commit 88f9a9f

Please sign in to comment.