1.3.0 • Published 9 years ago

gasync v1.3.0

Weekly downloads
5
License
BSD
Repository
github
Last release
9 years ago

Gasync

A library to easy you from writing callback functions with generators

Installation

npm install gasync --save

Usage

var http = require('http'); var Async = require('gasync'); var HttpResponse = function(res){ this.response = res; this.message = ''; }; HttpResponse.prototype = { read:function(callback){ this.callback = callback; this.response.on('data', this._data.bind(this)); this.response.on('end', this._done.bind(this)); }, _data:function(message){ this.message += message; }, _done:function(){ this.callback(this.message); } }; var HttpClient = function(writer){ this.writer = writer; };

HttpClient.prototype = { get: function*(async, host, port, path){ var options = { host: host, port: port, path: path, method: 'GET' }; var response = yield http.request(options, async.callback()).end(); var res = response0; this.writer('Status: ' + res.statusCode); this.writer('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); var chunk = yield new HttpResponse(res).read(async.callback()); this.writer(chunk0); } };

var httpClient = new HttpClient(console.log); new Async(httpClient.get).bind(httpClient, 'www.google.com', 80, '/') .then(new Async(httpClient.get).bind(httpClient, 'www.bing.com', 80, '/')) .then(new Async(httpClient.get).bind(httpClient, 'www.andytech.net', 80, '/index.html')) .run();

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago