Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorthand for collector.callback #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion do.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ const collect = (
isDone: false,
data: {}
};
const collector = (...args) => collector.collect(...args);
const collector = (...args) => {
if (args.length === 1) return collector.callback(args[0]);
return collector.collect(...args);
};
Object.setPrototypeOf(collector, Collector.prototype);
return Object.assign(collector, fields);
};
Expand Down
11 changes: 11 additions & 0 deletions test/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ tap.test('collect generate callback', (test) => {
af('someVal', col.callback('someKey'));
});

tap.test('collect generate callback shorthand', (test) => {
const col = collect(1);
col.done((err, res) => {
test.error(err);
test.strictSame(res, { someKey: 'someVal' });
test.end();
});
const af = (x, callback) => callback(null, x);
af('someVal', col('someKey'));
});

tap.test('collect with timeout error', (test) => {
const timeoutErr = new Error('Collector timeout');
const col = collect(1)
Expand Down