def sendRecordsToConnections()

in backend/lambda/question-stream/lambda.py [0:0]


def sendRecordsToConnections(recordsPerChannel, connectionsPerChannel):
    with ThreadPoolExecutor(max_workers=50) as executor:
        allPostsFutures = []
        for channel, connectionIds in connectionsPerChannel.items():
            for connectionId in connectionIds:
                allPostsFutures.append(
                    executor.submit(
                        postRecords, 
                        connectionId, 
                        recordsPerChannel[channel]
                    )
                )
                
        for future in as_completed(allPostsFutures):
            try :
                # To surface any exceptions
                future.result()
            except Exception as e:
                print(e)