question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

websocket send frame from non suspending progress listener

See original GitHub issue

Hello. I’m facing problem with webockets. I want to send frame each time my “manager” calls listener with progress.

        webSocket("/blockChainSyncProgress") {
            manager.addBlockChainProgressListener { progress ->
                launch {
                    outgoing.send(Frame.Text("$progress"))
                }
            }
        }

since the .addBlockChainProgressListener is not suspending function, websocket will close after the listener is added. I can add while (isActive) delay(1000) so the function looks like:

        webSocket("/blockChainSyncProgress") {
            manager.addBlockChainProgressListener { progress ->
                launch {
                    outgoing.send(Frame.Text("$progress"))
                }
            }
            while (isActive) delay(1000)
        }

but I’m not sure if it’s the recommended way of doing that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cy6erGn0mcommented, Nov 11, 2018

Also note that it looks like you are not unsubscribing: is that ok in your particular case? Shouldn’t you remove listener once a client get disconnected?

1reaction
cy6erGn0mcommented, Nov 11, 2018

The other alternative is to use a global instance of BroadcastConflatedChannel to publush manager’s current state and subscribe client’s session. Unfortunately this API is still experimental

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending and receiving frames over the same websocket ...
The problem is that when i use recv() while the data sending has already begun the server stops sending data and only waits...
Read more >
Using Pusher WebSockets To Show Progress During Page ...
Ben Nadel explores the use of Pusher WebSockets to indicate progress during the page unload / redirect experience in Lucee CFML 5.3.7.47.
Read more >
WebSocket.send() - Web APIs - MDN Web Docs - Mozilla
The WebSocket.send() method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value ...
Read more >
A Simple Multi-Client WebSocket Server - Forty Years of Code
Learn from this simple websocket server with realistic features. ... such as streaming video many never send an end-of-message frame.
Read more >
python-websockets(1) - Arch manual pages
#!/usr/bin/env python import asyncio import websockets async def echo(websocket): async for message in websocket: await websocket.send(message) async def ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found