Skip to content

Commit

Permalink
Fix argument passing issue in 1.0.0 and add a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed May 15, 2018
1 parent 156e0dd commit 8a9481a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions greenlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default function greenlet(asyncFunction) {
/* global $$ */

// Invoking within then() captures exceptions in the supplied async function as rejections
Promise.resolve().then(
$$.bind.apply($$, e.data)
Promise.resolve(e.data[1]).then(
v => $$.apply($$, v)
).then(
// success handler - callback(id, SUCCESS(0), result)
// if `d` is transferable transfer zero-copy
Expand Down
13 changes: 13 additions & 0 deletions greenlet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ describe('greenlet', () => {
expect(ret).toEqual('foo: test');
});

it('should forward arguments', async () => {
let foo = greenlet(function() {
return {
args: [].slice.call(arguments)
};
});

let ret = await foo('a', 'b', 'c', { position: 4 });
expect(ret).toEqual({
args: ['a', 'b', 'c', { position: 4 }]
});
});

it('should invoke async functions', async () => {
let bar = greenlet( a => new Promise( resolve => {
resolve('bar: '+a);
Expand Down

0 comments on commit 8a9481a

Please sign in to comment.