pax_global_header 0000666 0000000 0000000 00000000064 13467215565 0014530 g ustar 00root root 0000000 0000000 52 comment=4333f3ba00d0607d14e41089885f6af85298e483
teamwork-3.3.1/ 0000775 0000000 0000000 00000000000 13467215565 0013365 5 ustar 00root root 0000000 0000000 teamwork-3.3.1/.gitignore 0000775 0000000 0000000 00000000154 13467215565 0015360 0 ustar 00root root 0000000 0000000 **/node_modules
**/package-lock.json
coverage.*
**/.DS_Store
**/._*
**/*.pem
**/.vs
**/.vscode
**/.idea
teamwork-3.3.1/.travis.yml 0000775 0000000 0000000 00000000223 13467215565 0015476 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "8"
- "10"
- "12"
- "node"
sudo: false
install:
- "npm install"
os:
- "linux"
- "osx"
- "windows"
teamwork-3.3.1/CHANGELOG.md 0000664 0000000 0000000 00000000552 13467215565 0015200 0 ustar 00root root 0000000 0000000 Breaking changes are documented using GitHub issues, see [issues labeled "release notes"](https://github.com/hapijs/teamwork/issues?q=is%3Aissue+label%3A%22release+notes%22).
If you want changes of a specific minor or patch release, you can browse the [GitHub milestones](https://github.com/hapijs/teamwork/milestones?state=closed&direction=asc&sort=due_date).
teamwork-3.3.1/LICENSE.md 0000775 0000000 0000000 00000002675 13467215565 0015006 0 ustar 00root root 0000000 0000000 Copyright (c) 2015-2019, Sideway Inc, and project contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
teamwork-3.3.1/README.md 0000775 0000000 0000000 00000000447 13467215565 0014654 0 ustar 00root root 0000000 0000000
# teamwork
Wait for multiple callbacks
[](http://travis-ci.org/hapijs/teamwork)
teamwork-3.3.1/lib/ 0000775 0000000 0000000 00000000000 13467215565 0014133 5 ustar 00root root 0000000 0000000 teamwork-3.3.1/lib/index.d.ts 0000664 0000000 0000000 00000002013 13467215565 0016030 0 ustar 00root root 0000000 0000000 /**
* Configuration of the team work.
*/
export interface Options {
/**
* Number of meetings this team should attend before delivering work. Defaults to 1.
*/
meetings?: number;
}
type ElementOf = T extends (infer E)[] ? E : T;
export class Teamwork {
/**
* Start a new team work.
* @param options Configuration of the team work.
*/
constructor(options?: Options);
/**
* Resulting work when all the meetings are done.
*/
work: Promise;
/**
* Attend a single meeting.
* @param note An optional note that will be included in the work's results. If an error is provided, the work will be immediately rejected with that error.
*/
attend(note?: Error | ElementOf): void;
/**
* Wait for the current work to be done and start another team work.
* @param options New configuration of the team work.
*/
regroup(options?: Options) : Promise;
}
export default Teamwork;
teamwork-3.3.1/lib/index.js 0000775 0000000 0000000 00000002035 13467215565 0015603 0 ustar 00root root 0000000 0000000 'use strict';
const internals = {};
exports = module.exports = internals.Team = class {
constructor(options) {
this._init(options);
}
_init(options = {}) {
this.work = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
const meetings = options.meetings || 1;
this._meetings = meetings;
this._count = meetings;
this._notes = [];
}
attend(note) {
if (note instanceof Error) {
return this._reject(note);
}
this._notes.push(note);
if (--this._count) {
return;
}
return this._resolve(this._meetings === 1 ? this._notes[0] : this._notes);
}
async regroup(options) {
await this.work;
this._init(options);
}
};
Object.defineProperties(internals.Team, {
__esModule: {
value: true
},
default: {
value: internals.Team
},
Teamwork: {
value: internals.Team
}
});
teamwork-3.3.1/package.json 0000775 0000000 0000000 00000001070 13467215565 0015654 0 ustar 00root root 0000000 0000000 {
"name": "@hapi/teamwork",
"description": "Wait for multiple callback",
"version": "3.3.1",
"repository": "git://github.com/hapijs/teamwork",
"main": "lib/index.js",
"keywords": [
"async",
"flow control",
"callback"
],
"files": [
"lib"
],
"types": "lib/index.d.ts",
"dependencies": {},
"devDependencies": {
"@hapi/code": "5.x.x",
"@hapi/lab": "19.x.x"
},
"scripts": {
"test": "lab -a @hapi/code -t 100 -L -Y",
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html"
},
"license": "BSD-3-Clause"
}
teamwork-3.3.1/test/ 0000775 0000000 0000000 00000000000 13467215565 0014344 5 ustar 00root root 0000000 0000000 teamwork-3.3.1/test/index.js 0000775 0000000 0000000 00000005541 13467215565 0016021 0 ustar 00root root 0000000 0000000 'use strict';
const Code = require('@hapi/code');
const Lab = require('@hapi/lab');
const Teamwork = require('..');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('Team', () => {
describe('ES6 modules properties', () => {
it('the ES6 module marker is defined', () => {
expect(Teamwork.__esModule).to.be.true();
});
it('the default property is defined', () => {
expect(Teamwork.default).to.exist();
expect(Teamwork.default).to.shallow.equal(Teamwork);
});
it('the Teamwork property is defined', () => {
expect(Teamwork.Teamwork).to.exist();
expect(Teamwork.Teamwork).to.shallow.equal(Teamwork);
});
});
it('resolve when meeting is attended', async () => {
const team = new Teamwork();
setTimeout(() => {
team.attend();
}, 100);
await team.work;
});
it('resolve when all meetings are attended', async () => {
const team = new Teamwork({ meetings: 2 });
let count = '';
setTimeout(() => {
count += '1';
team.attend();
}, 100);
setTimeout(() => {
count += '2';
team.attend();
}, 150);
await team.work;
expect(count).to.equal('12');
});
it('resolve with a note', async () => {
const team = new Teamwork();
setTimeout(() => {
team.attend('1');
}, 100);
const note = await team.work;
expect(note).to.equal('1');
});
it('resolve with notes', async () => {
const team = new Teamwork({ meetings: 2 });
setTimeout(() => {
team.attend('1');
}, 100);
setTimeout(() => {
team.attend('2');
}, 150);
const notes = await team.work;
expect(notes).to.equal(['1', '2']);
});
it('rejects on first error', async () => {
const team = new Teamwork({ meetings: 2 });
setTimeout(() => {
team.attend(new Error('boom'));
}, 100);
setTimeout(() => {
team.attend('2');
}, 150);
await expect(team.work).to.reject('boom');
});
it('resets condition after initial condition met', async () => {
const team = new Teamwork({ meetings: 2 });
let count = '';
setTimeout(() => {
count += '1';
team.attend();
}, 100);
setTimeout(() => {
count += '2';
team.attend();
}, 150);
await team.regroup();
expect(count).to.equal('12');
setTimeout(() => {
count += '3';
team.attend();
}, 150);
await team.work;
expect(count).to.equal('123');
});
});
teamwork-3.3.1/test/index.ts 0000775 0000000 0000000 00000002065 13467215565 0016031 0 ustar 00root root 0000000 0000000 import * as Lab from '@hapi/lab';
import { Teamwork } from '..';
const { expect } = Lab.types;
// Constructor tests
expect.type(new Teamwork());
expect.type(new Teamwork({ meetings: 2 }));
expect.error(new Teamwork({ foo: true }));
expect.error(new Teamwork({ meetings: 'foo' }));
expect.type>(new Teamwork().work);
expect.type(await new Teamwork().work);
// Attend tests
expect.type(new Teamwork().attend());
expect.type(new Teamwork().attend(new Error()));
expect.type(new Teamwork().attend('foo'));
expect.type(new Teamwork().attend('foo'));
expect.error(new Teamwork().attend('foo'));
expect.error(new Teamwork().attend('foo'));
expect.type(new Teamwork<[boolean, string]>().attend('foo'));
// Work tests
expect.type>(new Teamwork().work);
expect.type>(new Teamwork().work);
expect.type>(new Teamwork().work);
// Regroup tests
expect.type>(new Teamwork().regroup());