Skip to content

Commit 7ff2223

Browse files
committed
v0.1.3 | Spread args through decorator
1 parent a00b574 commit 7ff2223

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/await-on.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function on(promise) {
2222
* @param {Function} wrapped Function to be decorated
2323
* @return {Function} Function decorated
2424
*/
25-
on.handler = (wrapped) => () => on(wrapped())
25+
on.handler = (wrapped) => (...args) => on(wrapped(...args))
2626

2727
//Promise type extension
2828
global.Promise.prototype.handle = function() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "await-on",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "really simple error handling with await/async",
55
"main": "lib/await-on.js",
66
"directories": {

test/core.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const on = require('../lib/await-on')
33
const ANSWER = 42
44
const ERROR = new Error('Need more time to figure that out')
55

6-
let waitOne = () => new Promise(resolve => setTimeout(()=>resolve(ANSWER),1000))
7-
let waitOneAndThrow = () => new Promise( (resolve,reject) => setTimeout(() => reject(ERROR),1000))
6+
let waitOne = (answer=ANSWER) => new Promise(resolve => setTimeout(() => resolve(answer),1000))
7+
let waitOneAndThrow = () => waitOne().then(res => Promise.reject(ERROR))
88

99
tap.test("on", async function (t) {
1010
t.plan(2)
@@ -26,6 +26,18 @@ tap.test("@handler", async function (t) {
2626
t.equal(res,ANSWER)
2727
})
2828

29+
tap.test("@handler (with args)", async function (t) {
30+
t.plan(2)
31+
32+
const waitOneHandle = on.handler(waitOne)
33+
34+
const [err,res] = await waitOneHandle(41)
35+
36+
t.notOk(err)
37+
t.equal(res,41)
38+
})
39+
40+
2941
tap.test("Promise.prototype.handle", async function (t) {
3042
t.plan(2)
3143

0 commit comments

Comments
 (0)