https://github.com/raininfall/callback-sandbox
a function wrapper to avoid exception pop to top
https://github.com/raininfall/callback-sandbox
Last synced: about 2 months ago
JSON representation
a function wrapper to avoid exception pop to top
- Host: GitHub
- URL: https://github.com/raininfall/callback-sandbox
- Owner: raininfall
- License: mit
- Created: 2016-10-28T04:56:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-28T08:55:35.000Z (over 9 years ago)
- Last Synced: 2026-05-02T01:36:16.306Z (about 2 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# callback-sandbox
[](https://travis-ci.org/RainInFall/callback-sandbox)
[](https://coveralls.io/github/RainInFall/callback-sandbox?branch=master)
A function wrapper to avoid exception pop to top, or callback when timeout
## Installation
```bash
$ npm install callback-sandbox
```
## Example
```javascript
var sandbox = createSandbox(function onError(err){
//Handle error
console.log(err);//something wrong
}, 2000/*timeout*/);
setTimeout(sandbox(function(err){
throw new Error("something wrong");
}, 1000);
```
## API
### createSandbox([onError][timeout])
* **onError** Call whem an unhandle exception occur in sandbox
* **timeout** Default timeout of sandbox
Create a sandbox.
### sandbox(fn, [timeout])
* **fn** Function to run in the sandbox
* **timeout** Timeout for this run.
Run function in sandbox and start timeout.