1.0.0 • Published 6 years ago

callback.flow v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

callback.flow

travis package downloads styled with prettier

Just Callback<x, a> interface definition for use with flow projects that interface with nodejs callback based APIs. Callback<x, a> is a function that can be used to report success or failure of the async operation:

If operation is succeeds callback must be invoked with two arguments first of type either null|void and second of type a - callback(null, value)

If operation is fails callback must be invoked with single argument of type x - callback(error)

Please note that success type paramater is optional and defaults to void there for callbacks that don't pass data back can be typed as Callback<string> and also be invoked as callback() to report success and callback('Oops') to report failure.

Usage

import type { Callback } from "callback.flow"

export const readAsync = (
  address: string,
  callback: Callback<Error, string>
): void => {
  if (isValid(address)) {
    // ....
    callback(null, content)
  } else {
    callback(new Error("Invalid Address"))
  }
}

Install

npm install callback.flow