Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace old README with link to docs.

  • Loading branch information...
commit 825115565586e1a12590a9bcb85d73a4e0c3175b 1 parent dc33038
@crandmck crandmck authored
Showing with 3 additions and 121 deletions.
  1. +3 −121 README.md
View
124 README.md
@@ -6,126 +6,8 @@
## Purpose
-Perform an unkown number of tasks recursively and in parallel. For example, reading all the files in a nested set of directories. Built in support for [domains](http://nodejs.org/api/domain.html) by inheriting directly from `EventEmitter`.
+Strong-task-emitter enables you to perform a number of tasks recursively and in parallel. For example, reading all the files in a nested set of directories. It has built-in support for [domains](http://nodejs.org/api/domain.html) by inheriting directly from `EventEmitter`.
-## Example
+Please see the [official documentation](http://docs.strongloop.com/display/DOC/Strong+Task+Emitter).
-The following example shows the basic API for a TaskEmitter.
-
- var TaskEmitter = require('../');
- var request = require('request');
- var results = [];
-
- var te = new TaskEmitter();
-
- te
- .task('request', request, 'http://google.com')
- .task('request', request, 'http://yahoo.com')
- .task('request', request, 'http://apple.com')
- .task('request', request, 'http://youtube.com')
- // listen for when a task completes by providing the task name
- .on('request', function (url, res, body) {
- results.push(Buffer.byteLength(body));
- })
- .on('progress', function (status) {
- console.log(((status.total - status.remaining) / status.total) * 100 + '%', 'complete');
- })
- .on('error', function (err) {
- console.log('error', err);
- })
- .on('done', function () {
- console.log('Total size of all homepages', results.reduce(function (a, b) {
- return a + b;
- }), 'bytes');
- });
-
-The next example highlights how TaskEmitter can be used to simplify recursive asynchronous operations. The following code recursively walks a social network over HTTP. All requests run in parallel.
-
- var TaskEmitter = require('../');
- var request = require('request');
- var socialNetwork = [];
-
- var te = new TaskEmitter();
-
- te
- // specify a task name
- .task('friends', fetch, 'me')
- .on('friends', function (user, url) {
- if(url !== 'me') {
- socialNetwork.push(user);
- }
-
- user.friendIds.forEach(function (id) {
- this.task('friends', fetch, 'users/' + id)
- }.bind(this));
- })
- .on('done', function () {
- console.log('There are a total of %n people in my network', socialNetwork.length);
- });
-
-
- function fetch(url, fn) {
- request({
- url: 'http://my-api.com/' + url,
- json: true,
- method: 'GET'
- }, fn);
- }
-
-## Extending TaskEmitter
-
-`TaskEmitter` is designed to be a base class which can be inherited from and extended by many levels of sub classes. The following example shows a class that inherits from TaskEmitter and provides recursive directory walking and file loading.
-
- var TaskEmitter = require('../');
- var fs = require('fs');
- var path = require('path');
- var inherits = require('util').inherits;
-
- function Loader() {
- TaskEmitter.call(this);
-
- this.path = path;
- this.files = {};
-
- this.on('readdir', function (p, files) {
- files.forEach(function (f) {
- this.task(fs, 'stat', path);
- }.bind(this));
- });
-
- this.on('stat', function (file, stat) {
- if(stat.isDirectory()) {
- this.task(fs, 'readdir', file);
- } else {
- this.task(fs, 'readFile', file, path.extname(file) === '.txt' ? 'utf-8' : null);
- }
- });
-
- this.on('readFile', function (path, encoding, data) {
- this.files[path] = data;
- });
- }
-
- inherits(Loader, TaskEmitter);
-
- Loader.prototype.load = function (path, fn) {
- if(fn) {
- // error events are handled if a task callback ever is called
- // with a first argument that is not falsy
- this.on('error', fn);
-
- // once all tasks are complete the done event is emitted
- this.on('done', function () {
- fn(null, this.files);
- });
- }
-
- this.task(fs, 'readdir', path);
- }
-
- // usage
- var l = new Loader();
-
- l.load('sample-files', function (err, files) {
- console.log(err || files);
- });
+For API reference documentation, see http://apidocs.strongloop.com/strong-task-emitter/.

0 comments on commit 8251155

Please sign in to comment.
Something went wrong with that request. Please try again.