Skip to content

Commit 8ae276e

Browse files
committed
fix(try-to-catch) wraptile -> noArg
1 parent a7b2afe commit 8ae276e

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/try-to-catch.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
'use strict';
22

3-
const wraptile = require('wraptile/legacy');
4-
53
const success = (a) => [null, a];
64
const fail = (a) => [a];
75

6+
const noArg = (f, a) => () => f(...a);
7+
88
module.exports = (fn, ...args) => {
99
check(fn);
1010

1111
return Promise.resolve()
12-
.then(wrap(fn, args))
12+
.then(noArg(fn, args))
1313
.then(success)
1414
.catch(fail);
1515
};
1616

17-
function wrap(fn, args) {
18-
if (!args.length)
19-
return fn;
20-
21-
return wraptile(fn, ...args);
22-
}
23-
2417
function check(fn) {
2518
if (typeof fn !== 'function')
2619
throw Error('fn should be a function!');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"legacy": "echo \"module.exports = require('./try-to-catch')\" > legacy/index.js"
2121
},
2222
"dependencies": {
23-
"wraptile": "^2.0.0"
2423
},
2524
"keywords": [
2625
"try",
@@ -41,7 +40,8 @@
4140
"nodemon": "^1.14.12",
4241
"nyc": "^13.0.1",
4342
"redrun": "^7.0.2",
44-
"tape": "^4.8.0"
43+
"tape": "^4.8.0",
44+
"try-to-tape": "^1.0.0"
4545
},
4646
"license": "MIT"
4747
}

test/try-to-catch.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
const test = require('tape');
3+
const {promisify} = require('util');
4+
const tryToTape = require('try-to-tape');
5+
const test = tryToTape(require('tape'));
46
const tryToCatch = require('..');
57

68
test('try-to-catch: no args', (t) => {
@@ -58,3 +60,11 @@ test('try-to-catch: resolves: not promise', async (t) => {
5860
t.end();
5961
});
6062

63+
test('try-to-catch: resolves: promisify', async (t) => {
64+
const fn = promisify((a, b, fn) => fn(null, a + b));
65+
const [, data] = await tryToCatch(fn, 1, 2);
66+
67+
t.equal(data, 3, 'should not be error');
68+
t.end();
69+
});
70+

0 commit comments

Comments
 (0)