Skip to content

Commit

Permalink
renamed flatten-promise to flatten-thunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Moshe Kolodny committed Apr 22, 2015
1 parent 7c7e879 commit 285db6f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
16 changes: 0 additions & 16 deletions flatten-promise/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions flatten-promise/test.js

This file was deleted.

43 changes: 43 additions & 0 deletions flatten-thunk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Here's the basic usage of the file that you'll be creating:

```js
var flattenThunk = require('./') // <- this is the file you make;

var thunk1 = function(cb) {
setTimeout(function() {
cb(null, 'done');
}, 1);
}
var thunk2 = function(cb) {
setTimeout(function() {
cb(null, thunk1);
}, 1);
}
var thunk3 = function(cb) {
setTimeout(function() {
cb(null, thunk2);
}, 1);
}

flattenThunk(thunk3)(function(err, result) {
console.log(result); // 'done'
});
```

A thunk is basically a function that you call with just the callback as a parameter:

```js

// this is a regular node CPS function
fs.readFile('package.json', function(err, result) {
console.log(result);
});

// this is a thunk
var readFileThunk = fs.readFileThunkily('package.json');
readFileThunk(function(err, result) {
console.log(result);
});
```

More info: https://github.com/tj/node-thunkify
File renamed without changes.
31 changes: 31 additions & 0 deletions flatten-thunk/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var assert = require('assert');
var flattenThunk = require('./');

describe('flattenThunk', function() {

it('flattens the promises', function(done) {

var thunk1 = function(cb) {
setTimeout(function() {
cb(null, 'done');
}, 1);
}
var thunk2 = function(cb) {
setTimeout(function() {
cb(null, thunk1);
}, 1);
}
var thunk3 = function(cb) {
setTimeout(function() {
cb(null, thunk2);
}, 1);
}

flattenThunk(thunk3)(function(err, result) {
assert.equal(result, 'done');
done();
});
});


});

0 comments on commit 285db6f

Please sign in to comment.