resultify

convert node functions to Result returning ones

npm install resultify
8 downloads in the last week
35 downloads in the last month

resultify

convert node functions to Result returning ones

Installation

With component, packin or npm

$ {package mananger} install jkroso/resultify

then in your app:

var resultify = require('resultify')

API

resultify(fn:Function)

Teach a node function all about the Result type

var readFile = resultify(fs.readFile)
readFile('/path/to/file.js', 'utf8').then(function(src){
  process.stdout.write(src)
})

fs

just a copy of the fs module from node but with all of the async functions run through the above function

Examples

Results are like dataflow variables. If all the functions in your program understand them you can hardly tell your code isn't blocking.

fs.readFile(prompt('which file? '), 'utf8').read(function(file){
    console.log(file)
})

Performance

once a function has been decorated with resultify it will incur an extra 700-1000ns per invocation which is nothing to worry about. To put that in perspective a function bound with .bind() will become 1500-2000ns slower. Tested on a mac air with node@v0.10.12

Running the tests

Just run make test

npm loves you