Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActorCoroutine with ConflatedBufferedChannel capactiy #4155

Closed
wjdtn7823 opened this issue Jun 13, 2024 · 1 comment
Closed

ActorCoroutine with ConflatedBufferedChannel capactiy #4155

wjdtn7823 opened this issue Jun 13, 2024 · 1 comment

Comments

@wjdtn7823
Copy link

wjdtn7823 commented Jun 13, 2024

Use case

I want to build a ActorCoroutine via a Channel with Conflated Behavior and capacity.
Reading the documentation, Channel should be build with capacity > 0 and, BufferOverFlow.DROP_OLDEST or BufferOverFlow.DROP_LATEST to accomplisth this.

public fun <E> Channel (
    capacity: Int = RENDEVZOUD,
    onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, // use BufferOverflow.DROP_LATEST or BufferOverflow.DROP_OLDEST
    onUndeliveredElement: ((E) ->Unit)? = null
)

However, the public actor API does not provide the way to build a Channel with BufferOverFlow Option

public fun <E> CoroutineScope.actor(
   context: CoroutineContext = EmptyCoroutineContext,
   capacity: Int = 0,
   start: CoroutineStart = CoroutineStart.DEFAULT,
   onCompletion: CompletionHandler? = null,
   block: suspend  ActorScope<E>.() -> Unit
): SendChannel<E> {
//
  val channel = Channel<E>(capacity) //  onBufferOverFlow default value is used
...

I tried to make a custom actor builder API, but ActorCoroutine and LazyActorCoroutine inside the actor builder is package private so this won't work. Is there a reason to restrict this behavior? or can you change the API like below?

The Shape of the API

public fun <E> CoroutineScope.actor(
    context: CoroutineContext = EmptyCoroutineContext,
    capacity: Int = 0,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    onCompletion: CompletionHandler ?= null,
    onBufferOverflow: BufferOverflow: BufferOverflow.SUSPEND, // add onBufferOverflow option
    block : suspend ActorScope<E>.() -> Unit
): SendChannel<E> {
//
 val channel = Channel<E>(capacity, onBufferOverflow)
//
@qwwdfsad
Copy link
Collaborator

Unfortunately, actors are obsolete APIs, and we would like to avoid evolving them further or promoting their usage.

Could you please elaborate on the use-case where the actor is allowed to drop messages from its mailbox?

@qwwdfsad qwwdfsad closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants