successerror
v0.0.2
Published
simplified optional success/error callbacks
Downloads
2
Readme
successerror
simplified optional success/error callbacks
Install
npm i successerror
Usage
import fs from 'fs'
import { SuccessErrorCallback, Solver } from './successErrorCallbacks';
// With these callbacks, functions like this can be created with optional callbacks
function remove(path: string, ...callbacks: SuccessErrorCallback[]) {
fs.unlink(path, Solver.with(callbacks).solve)
}
// So the functions can be called like this
const dummyPath = 'dummyPath'
// Order doesn't matter
remove(dummyPath,
(() => { console.log('success') }), // successCallback
(err => console.log(err)) // errorCallback
)
remove(dummyPath,
(err => console.log(err)), // errorCallback
(() => { console.log('success') }) // successCallback
)
// Use only success or only error callback
remove(dummyPath, (err => console.log(err))) // only errorCallback
remove(dummyPath, (() => { console.log('success') })) // only successCallback
// Use no callback
remove(dummyPath) // no callback