Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions kioto/channels/api.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
from __future__ import annotations

from typing import Awaitable, TypeVar

from kioto.channels import impl
from typing import Any

T = TypeVar("T")


def channel(capacity: int) -> tuple[impl.Sender, impl.Receiver]:
channel = impl.Channel(capacity)
def channel(capacity: int) -> tuple[impl.Sender[T], impl.Receiver[T]]:
channel: impl.Channel[T] = impl.Channel(capacity)
sender = impl.Sender(channel)
receiver = impl.Receiver(channel)
return sender, receiver


def channel_unbounded() -> tuple[impl.Sender, impl.Receiver]:
channel = impl.Channel(None)
def channel_unbounded() -> tuple[impl.Sender[T], impl.Receiver[T]]:
channel: impl.Channel[T] = impl.Channel(None)
sender = impl.Sender(channel)
receiver = impl.Receiver(channel)
return sender, receiver


def oneshot_channel():
channel = impl.OneShotChannel()
def oneshot_channel() -> tuple[impl.OneShotSender[T], Awaitable[T]]:
channel: impl.OneShotChannel[T] = impl.OneShotChannel()
sender = impl.OneShotSender(channel)
receiver = impl.OneShotReceiver(channel)
return sender, receiver()


def watch(initial_value: Any) -> tuple[impl.WatchSender, impl.WatchReceiver]:
channel = impl.WatchChannel(initial_value)
def watch(initial_value: T) -> tuple[impl.WatchSender[T], impl.WatchReceiver[T]]:
channel: impl.WatchChannel[T] = impl.WatchChannel(initial_value)
sender = impl.WatchSender(channel)
receiver = impl.WatchReceiver(channel)
return sender, receiver
Expand Down
Loading