Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return this.joinLock.wrapAll(channelNames, async () => {
let results: Record> = {};
let needToJoin: string[] = [];
for (let channelName of channelNames) {
if (this.channels.has(channelName)) {
results[channelName] = ok(this.roomStateTracker.getState(channelName) as RoomState);
} else {
needToJoin.push(channelName);
}
}
let promises: Promise[] = [];
let idx = 0;
while (idx < needToJoin.length) {
let conn = this.requireConnection(
c => c.channels.size < this.configuration.maxChannelCountPerConnection);
let canJoin = this.configuration.maxChannelCountPerConnection - conn.channels.size;
let slice = needToJoin.slice(idx, idx += canJoin);
promises.push((async () => {
return (p.then(r => ok(r), (e) => err(e))) as Promise>;
}