Code Monkey home page Code Monkey logo

futuresjs's Introduction

FuturesJS - The simple asynchronous toolkit.

It's a JavaScript flow-control library (or control-flow - however you like to say it) with the aim of being simple and intuitive.

It doesn't use promises in the strictest sense of the definition, but does help tame your wild, async code.

FuturesJS v3 (aka 'Diet Cola')

Status: Maintained, In Development

v3.x is simply an experiment in making FuturesJS more browser-friendly, simpler, smaller, and more intuitively obvious, even to the most casual observer!

For v3 each module has been split into its own repository in https://github.com/FuturesJS.

Completed thus far:

In progress:

FuturesJS v2

Status: Maintained

Don't worry, v2 is still supported and probably always will be.

https://github.com/FuturesJS/FuturesJS/tree/v2.0

The version isn't inactive. It's simply complete. If you do find a bug, however, please report it.

FuturesJS v1

Status: Deprecated

https://github.com/FuturesJS/FuturesJS/tree/v1.0

http://gh-pages.coolaj86.com/futures/

This version is not active, nor is it complete. If you find bugs, I don't want to hear about them.

futuresjs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

futuresjs's Issues

Backward compatibility broken

The update of join#3.0.0 broke futurejs#2.3.1

Any ideia how to keep to older version of join when installing futures?

I thought about generating another version of futures#2.3.3 using ~ to declare its dependencies.

`Join` needs a `map` function

Current Usage:

join.when(function (args0, args1, args2) {
  var a1 = args0[0]
    , b1 = args0[1]
    , a2 = args1[0]
    , b2 = args1[1]
    ...
});

Possible Usage:

function mapArgs() {
  return { a: a, b: b, c: c };
}

function cb(args0, args1) {
  var a1 = args0.a
    , a2 = args1.a
    ;
  ...
}

join.when(cb, mapArgs);

needs `forEachJoin` to complement `forEachAsync`

I find that I use forEachAsync much more often than Sequence. Join needs a similar complement, something like one of these:

forEachAsync(arr, fn, { parallel: true });

forEachAsync(arr, fn, { join: true });

forEachJoin(arr, fn);

add count to futures/sequence

it'd be nice to know how many items are currently in the stack, how many have been added total, and how many have been processed.

Expose next to sequence()

This way you can do something like

sequence = Futures.sequence()

emitter.on 'callback', ->
    sequence.next(err)

sequence
    .then (next, err) ->
        # do something
    .then (next, err) ->
        ...

Perhaps also a way to set the sequence back 1 (or however many)? Could really use that also.

Option not to throw errors

I wanted a way to not throw errors. I'd rather log them and do something with them via a callback.

I forked and added an options parameter to the future constructor. If there is a function options.error, I send the error there; if not, throw the error per the original code. I'll send you a pull request in case you want the code.

Here is an example of it in action: https://gist.github.com/1635365

require without npm doesn't seem to work

It seems that the require system in node.js doesn't play nice with futures. The directory structure is futures/lib/private etc but the require statements involve futures/private. I use submodule instead of npm for my project.. so i haven't tried the suggested npm install.

I think that's where the 'provide' method comes in but somehow node is still complaining. Not sure if it matters but I'm using [email protected].

contacts-workshop sample fails on Google Chrome and IE8

The browser-exmaples\contacts-workshop-utos2010/index.html sample fails on Google Chrome with: Uncaught TypeError: Object function Array() { [native code] } has no method 'concat'

It also fails on IE8.

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Sun, 28 Nov 2010 23:19:10 UTC

Message: Invalid character
Line: 1
Char: 1
Code: 0
URI: file:///S:/Libs/JS/coolaj86-futures-v0.9.8-0-gdf8747e/coolaj86-futures-df8747e/browser-exmaples/contacts-workshop-utos2010/libs/app.js

Works ok on Firefox 3.6.12

  • Neville

running node-example produce warning

When I run the node-example exec-shell-script.js i get the following error:

'fail' is deprecated, please use when(err, data) instead
'fail' is deprecated, please use when(err, data) instead
'fail' is deprecated, please use when(err, data) instead

It's coming from promise.js.

Any ideas?

chainify example error

Hi,

I tried to run the chainify.js in examples. The output is like

This is a visual test.
[Function: Chainify]

one
Pass: provider params == provider params

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: next is not defined
at futures/futures/chainify.js:50:20
at next (futures/futures/sequence.js:30:20)
at sequence.then (futures/futures/sequence.js:46:14)
at Object.caps (futures/futures/chainify.js:47:20)
at futures/examples/chainify.js:46:32
at Object. (futures/examples/chainify.js:51:1)
at Module._compile (module.js:404:26)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)

I have changed the require from local file path to futures in npm. The error is the same. Any idea?

I am on [email protected] and [email protected].

Thanks,

Dong

Test.html issues

Latest 0.98-3 release and previous 0.98-0 release.

They use '../vendor/underscore/underscore.js' which isn't in the download zip file.

Further they use futures.deprecated.js not future.all.js as per the readme.md file.

There are multiple logs of: fail' is deprecated, please use when(err, data) instead

If I change it to use: futures.all.js it fails on
"Futures.promisify(func).withResult(syncback) - Original result" Failed
with:
Uncaught TypeError: Object # has no method 'promisify' test.html line 154.

There appears to be various implementations of futures.js in the download zip file.

-Neville

[enhancement] Add missing bower.json.

Hey, maintainer(s) of FuturesJS/FuturesJS!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library FuturesJS/FuturesJS is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "FuturesJS/FuturesJS",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

How do I get the data of a future (in sync mode)?

I have the following code that is into a render. The render will wait for a image to load in order to render the scene, therefore this code takes care of. But in the case the image is already loaded how I might get access to it, without using another method?
It would be really useful to have: imageFuture.getData(); that returns the last data.
I could do the imageFuture.when(function(){render here!!}); but doesn't seems the way to do it. It would be more natural to have the getData() method.

    ,__renderImage: function(imageNode){
        var imageFuture = this.__imageStore.getImage(imageNode.getPath());
        if(imageFuture.deliveryCount() > 0){
            // render
            var ctx = this.__defaultCanvas.getContext2d();
            var x = imageNode.getAbsoluteX(); 
            var y = imageNode.getAbsoluteY();
            ctx.drawImage(imageData, x, y, imageNode.getWidth(), imageNode.getHeight());
        }else{
            if(!this.__pendingImagesNodes){
                this.__pendingImagesNodes = [];
            }
            if(this.__pendingImagesNodes.indexOf(imageNode) != -1){
                return;
            }
            this.__pendingImagesNodes.push(imageNode);
            imageFuture.when(function(data){
                imageNode.invalidate();
            });
        }
    }

Handling errors with Join

Reading the documentation I can't understand how are errors handled with join. This is the example provided:

var Join = require('join')
  , join = Join.create()
  , callbackA = join.add()
  , callbackB = join.add()
  , callbackC = join.add()
  ;

function abcComplete(aArgs, bArgs, cArgs) {
  console.log(aArgs[1] + bArgs[1] + cArgs[1]);
}

setTimeout(function () {
  callbackA(null, 'Hello');
}, 300);

setTimeout(function () {
  callbackB(null, 'World');
}, 500);

setTimeout(function () {
  callbackC(null, '!');
}, 400);


// this must be called after all 
join.when(abcComplete);

All the callbacks are called with a null error, but what if an error exists. How can I handle the error in the following code:

var Join = require('join')
  , join = Join.create()
  , callbackA = join.add()
  , callbackB = join.add()
  , callbackC = join.add()
  ;

function abcComplete(aArgs, bArgs, cArgs) {
  console.log(aArgs[1] + bArgs[1] + cArgs[1]);
}

setTimeout(function () {
  callbackA(null, 'Hello');
}, 300);

setTimeout(function () {
  callbackB(new Error("Example"), 'World');
}, 500);

setTimeout(function () {
  callbackC(null, '!');
}, 400);


// this must be called after all 
join.when(abcComplete);

I guess it will be useful if I could enter a callback to handle the error. I guess this is a typical use case, but I can't find how to do this in the documentation.

Make a way to avoid changing the prototype

Some people may be adverse to messing with Array's prototype. I'm totally cool with it, but you gotta make everyone happy.

Anyway, do you think you could make a way to have the same functionality, but pass in the array instead of calling the forEachAsync method of the array? That would be awesome.

provide jsDoc

it would be great to have documentation in jsDoc format. It will allow to use code completion and tooltips in some IDEs, for example Eclipse WTP javascript editor.

setTimeout and fulfill

I was trying to use setTimeout() as a "timeout" error for my async function. However, if the function fulfill()-ed the future first, an error is generated when the setTimeout() fires.

I got around this by using deliver() and when() instead of fulfill(),

Was I using setTimeout() with the wrong expectations, or should it check if the future has been fulilled before firing it's event?

Cheers
Paul

lazy addition of parallels using Futures.join().add()

Idea inspired by funky

var join = Futures.join(); // allow zero promises to start with
var fulfill = join.add(asapCallback); // return the fulfill of the promise, add the `when`
var fulfill2 = join.add(asapCallback2);

join.when(function (args1, args2) {
    var err = args1[0] || args2[0]; // err was the first argument of both
    if (err) { throw new Error("youch!"); }
    // do stuff with the data portion
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.