async javascript framework with #future.js for #client and #server

Oscar Brito


Be sure you use future.js patterns to create awesome code.

  • Events
  • Promises
  • Chainify
  • Sequence aka "then"

Events:



var Emitter = require("emitter"),
emitter = Emitter();

emitter.on("foo", function (data) {
console.log(data);
});

emitter.emit("foo", "bar");


Chainify:



var Chainify = require("chainify"),

providers = {
all: function (next, query) {
console.log("Pass: provider params == ", query);
next("Mvndaai", "555-555-5555");
}
};

modifiers = {
decaps: function (next, nombre, numero, params) {
console.log("Pass: modifier params == ", params);
next(nombre.toLowerCase(), numero.toLowerCase());
}
};

consumers = {
print: function (nombre, numero, transform) {
var msg = transform(nombre);
console.log(msg, numero);
}
};

// creates a chainify
model = Chainify(providers, modifiers, consumers);

// combine methods
model.all("provider params").decaps("modifier params").print(function (str) { return ("Pass: " + str); });


Promises:



var Promise = require("future"),

promise.when(function (err, data) {
console.log(data);
});

promise.fulfill(undefined, "hello world");

promise.when(function (err, data) {
console.log(data);
});

promise.fulfill(undefined, "end-of-the-world");


Sequence



var sequence = require('sequence').create()

sequence
.then(function (next) {
setTimeout(function () {
next(err, "Hi", "World!");
}, 120);
})


https://github.com/coolaj86/futures



Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.