Oneshot¤
A channel that can send a single message.
A one-shot channel is a channel that can only send one message. After the first
message is sent, the sender is closed and any further attempts to send a message
will raise a SenderClosedError.
Sending a message from one task to another
import asyncio
from frequenz.channels import OneshotChannel, OneshotSender
async def send(sender: OneshotSender[int]) -> None:
await sender.send(42)
async def main() -> None:
sender, receiver = OneshotChannel[int]()
async with asyncio.TaskGroup() as tg:
tg.create_task(send(sender))
assert await receiver.receive() == 42
asyncio.run(main())