exec-fallback
fallback to executable if a method call falls.
Last updated 5 years ago by leichtgewicht .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install exec-fallback 
SYNC missed versions from official npm registry.

exec-fallback Build Status

Tool to fallback to an exec command in case that a method doesn't return a satisfactory value

Usage

Install with ...

$ npm install exec-fallback --save

and create a fallback in case a synchronous template is empty:

var fb = require('exec-fallback')
var myFallback = fb(function () {
    // do something
}, 'fallback-command')

Here is a example where pwd is called in case a config.path property doesn't exist.

var fb = require('exec-fallback')
function regularCall() {
    return config.path
}
var myConfigPath = fb(regularCall, 'pwd')

since the fallback is an async exec command you need to register a callback hook to get the value

myConfigPath(function (error, value) {
  // there will never be an error,
})

Caching & Invalidation

The result will be cached by default for 10 minutes. You can change the cache time by passing in a third parameter.

var myConfigPath = fb(regularCall, 'pwd', 100000)

It is also possible to invalidate the currently cached value.

myConfigPath.invalidate()

License

ISC

Originally inspired by osenv.

Current Tags

  • 1.2.2                                ...           latest (5 years ago)

7 Versions

  • 1.2.2                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 2
Last Day 0
Last Week 1
Last Month 2
Dependencies (0)
None
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |