1.2.0 • Published 11 years ago

yld v1.2.0

Weekly downloads
84
License
-
Repository
github
Last release
11 years ago

yld

A JavaScript promises alternative, under the MIT License.

Concept :

yld (pronounced "yielded") is tool based on that keyword.

Contrary to promises, which grow to declare a lot of functions to disorganize your code, yld allows you to execute instructions written in a linear list.

Each yield pauses the process and allows to retrieve a response from another function ... could easily be compared to a promise.then().

The yld function :

var yielded = yld(closure);
yielded(/* closure arguments */);

The closure structure :

Create a step :

var closure;

closure = function () {
    yield; // this makes a step
};

Retrieve a response form an other scope :

var closure

closure = function () {
    var response;

    response = yield;
};

The closure properties :

Object this.parent

The parent yielded scope (parent.send() & parent.yld()), if current scope is created by this.yld(), else returns undefined

String set this.error()

Kills immediately the current process

var closure;

closure = function () {
    this.error = 'error message'; // throws the error message
    yield; // unreached point
};

Function this.send()

Send variables to the next yield response

var closure;

closure = function () {
    var response;

    this.send(123);
    response = yield; // response is 123
};

Function this.yld()

Your this context knows yld as internal method

var closure;

closure = function () {
    var yielded, response;
    
    yielded = this.yld(function (/* args */) {
        // here, the this.parent.send() is used to send a response to the parent scope
        this.parent.send(123);
    });
    
    response = yield yielded(/* args */); // response is 123
};

Requirements :

yield keyword support ES5 Object methods

1.2.0

11 years ago

1.1.9

11 years ago

1.1.8

11 years ago

1.1.7

11 years ago

1.1.6

11 years ago

1.1.5

11 years ago

1.1.4

11 years ago

1.1.3

11 years ago

1.1.2

11 years ago

1.1.1

11 years ago

1.1.0

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago