[channels 2] Send to a single channel from sync code
See original GitHub issuechannel_layer.send
seems to be an async function. So how would I call it from sync code? Should asgiref.sync.async_to_sync
be used in such case?
Also docs don’t mention it being async.
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (16 by maintainers)
Top Results From Across the Web
What's new in Channels 2? — Channels 2.4.0 documentation
Channels 1 and Channels 2 are substantially different codebases, ... only jumping to synchronous code when you interact with the Django view system...
Read more >std::sync::mpsc - Rust
These channels come in two flavors: An asynchronous, infinitely buffered channel. The channel function will return a (Sender, Receiver) tuple where all sends...
Read more >Sending different types using same Rust channel (mpsc)
One particular channel can only send one type of data. As you noticed, your sender has the type Sender<String> and the receiver has...
Read more >Module mpsc - tokio::sync - Docs.rs
A multi-producer, single-consumer queue for sending values between asynchronous tasks. This module provides two variants of the channel: bounded and ...
Read more >Channels | Tokio - An asynchronous Rust runtime
We could use tokio::sync::Mutex , but that would only allow a single in-flight ... Now, update the two tasks to send commands over...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve got another problem. Wrapping with
AsyncToSync
works only if we are somewhere in asgi app. If I call wrapped function from another process (management command for example) then it fails withCannot call async functions without an event loop running
. If I call it from another process which has its own asyncio loop then it just hangs.As example, I have the following function:
I’d like it to be multipurpose, and avoid writing 3 different versions of this function. Can something be done about this?
I’ll try and clean that up if I can replicate the environment it happens in (I already fixed one hanging issue yesterday, but it makes my brain hurt a bit so I need a short break)