Last active
January 3, 2016 22:59
-
-
Save EvanCarroll/8531891 to your computer and use it in GitHub Desktop.
Thunk fun.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thunkify = require('./index.js'); | |
function wtf ( cb ) { | |
console.log('start'); | |
// Function, expecting callback triggers twice | |
cb( 'HELLO 1' ); | |
cb( 'HELLO 2' ); | |
cb( 'HELLO 3' ); | |
console.log('done'); | |
return; | |
} | |
var thunk = thunkify(wtf); // now we have thunk | |
var invoke = thunk(); // now we invoke without any args, or callback | |
setTimeout( function () { | |
// Now we set callback. | |
invoke( | |
function () { console.log( 'good', arguments ) } | |
); | |
} ,1000 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment