Skip to content

Feature: Go-like (val, ok) handler deduction for select #71

Description

@mzfhhhh

Title: Feature: Go-like (val, ok) handler deduction for select

Motivation

Currently, consuming data inside a select handler requires manually checking channel state and popping:

select(ch, {
    if (!ch.ready) { /* closed */ }
    else {
        auto val = ch.front;
        ch.popFront;
    }
});

This is verbose and error-prone. It would be great to mimic Go's val, ok := <-ch mental model, which is widely understood and very LLM-friendly.

Proposal

Utilize D's compile-time reflection to deduce the handler's signature.
1. (val, ok) style (Safe and explicit):

select(ch, (int val, bool ok) {
    if (ok) { 
        // Process val 
    } else { 
        // Channel closed and drained 
    }
});

2. val only style (Convenient, val is T.init if closed):

select(ch, (int val) {
    // Process val (might be T.init if closed)
});

This significantly improves DX and aligns perfectly with standard concurrency mental models.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions