Skip to content

Feature Request: Add Non-blocking trySend() and tryReceive() to Channel #187

@magicprinc

Description

@magicprinc

At least trySend() 🙏

TL;DR
Add non-blocking trySend(T) and tryReceive() methods to Channel to enable integration with NIO frameworks (Netty, Vert.x, etc.), where blocking the event loop thread is prohibited.

  • Should return immediately without parking the virtual thread
  • Must be safe to call from platform threads (event loops)
  • Should respect channel capacity: return false/full for full buffered channels
  • Consider atomic operations for rendezvous channels (immediate failure if no waiting receiver)

e.g:

vertx.eventBus().consumer("events", msg -> {
    // Non-blocking channel operation in event loop
    if (channel.trySend(msg.body())) {
        msg.reply("Accepted");
    } else {
        msg.reply("Channel full, backpressure applied");
    }
});

Kotlin provides https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/try-send.html and tryReceive() returning ChannelResult

Project Reactor has tryEmitNext() for similar NIO integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions