From be873af003817f7b29ddbd44a4218716d94479dd Mon Sep 17 00:00:00 2001 From: Jack Mordaunt Date: Thu, 5 Jun 2025 15:29:10 -0300 Subject: [PATCH] core/sync.select_raw: rename to try_select_raw This follows the convention where non-blocking operations are prefixed with "try" to indicate as much. Since select_raw in it's current form doesn't block, it should be try_select_raw, and allow select_raw to name a blocking implementation. --- core/sync/chan/chan.odin | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/sync/chan/chan.odin b/core/sync/chan/chan.odin index 610cf16eb..df8dea43b 100644 --- a/core/sync/chan/chan.odin +++ b/core/sync/chan/chan.odin @@ -1116,12 +1116,14 @@ Select_Status :: enum { /* -Attempts to either send or receive messages on the specified channels. +Attempts to either send or receive messages on the specified channels without blocking. `select_raw` first identifies which channels have messages ready to be received and which are available for sending. It then randomly selects one operation (either a send or receive) to perform. +If no channels have messages ready, the procedure is a noop. + Note: Each message in `send_msgs` corresponds to the send channel at the same index in `sends`. **Inputs** @@ -1154,18 +1156,18 @@ Example: // where the value from the read should be stored received_value: int - idx, ok := chan.select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) + idx, ok := chan.try_select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) fmt.println("SELECT: ", idx, ok) fmt.println("RECEIVED VALUE ", received_value) - idx, ok = chan.select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) + idx, ok = chan.try_select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) fmt.println("SELECT: ", idx, ok) fmt.println("RECEIVED VALUE ", received_value) // closing of a channel also affects the select operation chan.close(c) - idx, ok = chan.select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) + idx, ok = chan.try_select_raw(receive_chans[:], send_chans[:], msgs[:], &received_value) fmt.println("SELECT: ", idx, ok) } @@ -1179,7 +1181,7 @@ Output: */ @(require_results) -select_raw :: proc "odin" (recvs: []^Raw_Chan, sends: []^Raw_Chan, send_msgs: []rawptr, recv_out: rawptr) -> (select_idx: int, status: Select_Status) #no_bounds_check { +try_select_raw :: proc "odin" (recvs: []^Raw_Chan, sends: []^Raw_Chan, send_msgs: []rawptr, recv_out: rawptr) -> (select_idx: int, status: Select_Status) #no_bounds_check { Select_Op :: struct { idx: int, // local to the slice that was given is_recv: bool,