Skip to content

Commit

Permalink
Prevent Promises from catching my errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed May 7, 2017
1 parent 05b4819 commit 2991699
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/encase-p.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import {noop, show, showf, partial1, partial2, partial3} from './internal/fn';
import {isThenable, isFunction} from './internal/is';
import {invalidArgument, typeError} from './internal/throw';

function escape(f){
return function imprisoned(x){
setTimeout(function escaped(){ f(x) }, 0);
};
}

function check$promise(p, f, a, b, c){
return isThenable(p) ? p : typeError(
'Future.encaseP expects the function its given to return a Promise/Thenable'
Expand All @@ -15,25 +21,25 @@ function check$promise(p, f, a, b, c){

function EncaseP$0$fork(rej, res){
const {_fn} = this;
check$promise(_fn(), _fn).then(res, rej);
check$promise(_fn(), _fn).then(escape(res), escape(rej));
return noop;
}

function EncaseP$1$fork(rej, res){
const {_fn, _a} = this;
check$promise(_fn(_a), _fn, _a).then(res, rej);
check$promise(_fn(_a), _fn, _a).then(escape(res), escape(rej));
return noop;
}

function EncaseP$2$fork(rej, res){
const {_fn, _a, _b} = this;
check$promise(_fn(_a, _b), _fn, _a, _b).then(res, rej);
check$promise(_fn(_a, _b), _fn, _a, _b).then(escape(res), escape(rej));
return noop;
}

function EncaseP$3$fork(rej, res){
const {_fn, _a, _b, _c} = this;
check$promise(_fn(_a, _b, _c), _fn, _a, _b, _c).then(res, rej);
check$promise(_fn(_a, _b, _c), _fn, _a, _b, _c).then(escape(res), escape(rej));
return noop;
}

Expand Down

0 comments on commit 2991699

Please sign in to comment.