Skip to content

YannickDot/Taskify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Taskify

util.promisify but for Tasks ! ๐Ÿ™Œ

Install

yarn add util.taskify

or

npm install util.taskify

โš ๏ธ You must give taskify the Task data type of your choice.

I suggest you to try Fluture or Taskorama.

Usage

For a single function :

const taskify = require('util.taskify')
const fs = require('fs')
const Task = require('taskorama')
// or
// const Task = require('fluture')

const readFileTask = taskify(Task, fs.readFile)

readFileTask('package.json', 'utf8')
  .fork(
    err => console.error('Failed.', err),
    str => console.log('Done!', str)
  )

Or for a whole module :

const taskify = require('util.taskify')
const fs = require('fs')
const Task = require('taskorama')
// or
// const Task = require('fluture')

const Filesystem = taskify(Task, fs)

Filesystem.readFile('package.json', 'utf8')
  .fork(
    err => console.error('Failed.', err),
    str => console.log('Done!', str)
  )

BONUS

If you like currying (using ramda curry() function) :

const { curry } = require('ramda')
const util_taskify = require('util.taskify')
const fs = require('fs')
const Task = require('taskorama')
// or
// const Task = require('fluture')
//

const taskify = curry(util_taskify)
const taskifier = taskify(Task)

const readFileTask = taskifier(fs.readFile)

readFileTask('package.json')
  .fork(
    err => console.error('Failed.', err),
    str => console.log('Done!', str)
  )