import defer from 'p-defer';
/**
 * A pair of streams where one drains from the other
 */
export function pair() {
    const deferred = defer();
    let piped = false;
    return {
        sink: async (source) => {
            if (piped) {
                throw new Error('already piped');
            }
            piped = true;
            deferred.resolve(source);
        },
        source: (async function* () {
            const source = await deferred.promise;
            yield* source;
        }())
    };
}
//# sourceMappingURL=index.js.map