Sourabh Rawat
fun openWebSocket(scope: CoroutineScope = GlobalScope, consumer: JsonRpcListener) { scope.launch { <http://httpClient.ws|httpClient.ws>(method = HttpMethod.Get, host = host, port = port, path = path) { incoming.consumeAsFlow() .onEach { consumer.run(it) } .collect() } } }
e5l
collect()
launch { delay(....) // or suspend for some condition outgoing.close() }
launch
outgoing
SendChannel<Frame>
incoming
fun openWebSocket(scope: CoroutineScope = GlobalScope, listener: JsonRpcListener): () -> Unit { val job = scope.launch { <http://httpClient.ws|httpClient.ws>(method = HttpMethod.Get, host = host, port = port, path = path) { incoming.consumeAsFlow() .onEach { listener(it) } .collect() } } return { job.cancel() } }
RemoveListener
A modern programming language that makes developers happier.