"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForAssignmentsToPropagate = void 0;
const protocol_1 = require("@streamr/protocol");
async function waitForAssignmentsToPropagate(messages, targetStream, loggerFactory) {
    const foundPartitions = new Set;
    for await (const msg of messages) {
        const streamPart = msg.content.streamPart;
        try {
            const streamPartId = protocol_1.StreamPartIDUtils.parse(streamPart);
            const [streamId, partition] = protocol_1.StreamPartIDUtils.getStreamIDAndPartition(streamPartId);
            if ((streamId === targetStream.id) && (partition < targetStream.partitions)) {
                foundPartitions.add(partition);
                if (foundPartitions.size === targetStream.partitions) {
                    return;
                }
            }
        }
        catch {
            loggerFactory.createLogger(module).debug('Ignore malformed content');
        }
    }
}
exports.waitForAssignmentsToPropagate = waitForAssignmentsToPropagate;
//# sourceMappingURL=waitForAssignmentsToPropagate.js.map