Skip to content

Instantly share code, notes, and snippets.

View sktt's full-sized avatar

Johannes Wikner sktt

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sktt on github.
  • I am jwknr (https://keybase.io/jwknr) on keybase.
  • I have a public key whose fingerprint is 978C 6F9A 69CB CE2F 915D AD0A 5846 66DF 8F0E AAF4

To claim this, I am signing this object:

@sktt
sktt / promisify.js
Last active July 29, 2016 01:51
Tiny promisify function
/**
* Promisify a node style async func.
*
* @param {function} f Function to with a node callback as its last argument.
* @param [{object}] scope Scope to run `f` in, if necessary.
* @return {Promise}
*
* @example ```
* const read = promisify(fs.readFile, fs);
* read('./file')
@sktt
sktt / task_runner.js
Last active November 27, 2016 13:05
This is a pretty clean way to run sync and async tasks using Promise and a reducer func
module.exports = run
// Run tasks in sequence or async can be done in a very expressive way using
// Promise and a reducer
function run(tasks) {
return tasks.reduce(
(acc, task) => acc.then(lastResult => {
if (typeof task === 'function') {
// A task is a function that takes a result from a previous task and returns
// a promise executor function