File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff 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
2828global . Promise . prototype . handle = function ( ) {
Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ const on = require('../lib/await-on')
33const ANSWER = 42
44const 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
99tap . 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+
2941tap . test ( "Promise.prototype.handle" , async function ( t ) {
3042 t . plan ( 2 )
3143
You can’t perform that action at this time.
0 commit comments