pax_global_header00006660000000000000000000000064134672155650014530gustar00rootroot0000000000000052 comment=4333f3ba00d0607d14e41089885f6af85298e483 teamwork-3.3.1/000077500000000000000000000000001346721556500133655ustar00rootroot00000000000000teamwork-3.3.1/.gitignore000077500000000000000000000001541346721556500153600ustar00rootroot00000000000000**/node_modules **/package-lock.json coverage.* **/.DS_Store **/._* **/*.pem **/.vs **/.vscode **/.idea teamwork-3.3.1/.travis.yml000077500000000000000000000002231346721556500154760ustar00rootroot00000000000000language: node_js node_js: - "8" - "10" - "12" - "node" sudo: false install: - "npm install" os: - "linux" - "osx" - "windows" teamwork-3.3.1/CHANGELOG.md000066400000000000000000000005521346721556500152000ustar00rootroot00000000000000Breaking 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.md000077500000000000000000000026751346721556500150060ustar00rootroot00000000000000Copyright (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.md000077500000000000000000000004471346721556500146540ustar00rootroot00000000000000 # teamwork Wait for multiple callbacks [![Build Status](https://secure.travis-ci.org/hapijs/teamwork.png)](http://travis-ci.org/hapijs/teamwork) teamwork-3.3.1/lib/000077500000000000000000000000001346721556500141335ustar00rootroot00000000000000teamwork-3.3.1/lib/index.d.ts000066400000000000000000000020131346721556500160300ustar00rootroot00000000000000/** * 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.js000077500000000000000000000020351346721556500156030ustar00rootroot00000000000000'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.json000077500000000000000000000010701346721556500156540ustar00rootroot00000000000000{ "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/000077500000000000000000000000001346721556500143445ustar00rootroot00000000000000teamwork-3.3.1/test/index.js000077500000000000000000000055411346721556500160210ustar00rootroot00000000000000'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.ts000077500000000000000000000020651346721556500160310ustar00rootroot00000000000000import * 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());