[m-rev.] for review: Change interface of closeable_channel.try_take.

Peter Wang novalazy at gmail.com
Fri Apr 17 17:04:07 AEST 2020


library/thread.closeable_channel.m:
    Rename the `empty' result of closeable_channel.try_take to
    `would_block'.

tests/hard_coded/closeable_channel_test.exp:
tests/hard_coded/closeable_channel_test.m:
    Update test case.
---
 library/thread.closeable_channel.m          | 9 ++++++---
 tests/hard_coded/closeable_channel_test.exp | 2 +-
 tests/hard_coded/closeable_channel_test.m   | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/library/thread.closeable_channel.m b/library/thread.closeable_channel.m
index 7b9677d83..b14996a6a 100644
--- a/library/thread.closeable_channel.m
+++ b/library/thread.closeable_channel.m
@@ -53,11 +53,14 @@
 :- type try_take_result(T)
     --->    ok(T)
     ;       closed
-    ;       empty.
+    ;       would_block.
 
     % Take an item from the start of the channel, but do not block.
     % Returns `ok(Item)' if `Item' was taken from the channel,
-    % `empty' if the channel is empty, or `closed' if the channel is closed.
+    % `closed' if no item was taken because the channel is closed, or
+    % `would_block' if no item could be taken from the channel without
+    % blocking. `would_block' may be returned even if the channel is not
+    % empty.
     %
 :- pred try_take(closeable_channel(T)::in, try_take_result(T)::out,
     io::di, io::uo) is det.
@@ -150,7 +153,7 @@ try_take(channel(Read, _Write), Res, !IO) :-
         )
     ;
         TryRead = no,
-        Res = empty,
+        Res = would_block,
         NewHead = Head
     ),
     mvar.put(Read, NewHead, !IO).
diff --git a/tests/hard_coded/closeable_channel_test.exp b/tests/hard_coded/closeable_channel_test.exp
index 3f8888ffb..1f29a435f 100644
--- a/tests/hard_coded/closeable_channel_test.exp
+++ b/tests/hard_coded/closeable_channel_test.exp
@@ -1,6 +1,6 @@
 main: starting worker threads
 main: try_take...
-main: try_take - empty channel
+main: try_take - would block (possibly empty)
 main: put 1...
 main: put 1
 main: put 2...
diff --git a/tests/hard_coded/closeable_channel_test.m b/tests/hard_coded/closeable_channel_test.m
index 2a8ebc1cf..2070c33fd 100644
--- a/tests/hard_coded/closeable_channel_test.m
+++ b/tests/hard_coded/closeable_channel_test.m
@@ -191,8 +191,8 @@ trace_try_take(Log, Ch, TakeResult, !IO) :-
         TakeResult = closed,
         log(Log, "try_take - channel closed", !IO)
     ;
-        TakeResult = empty,
-        log(Log, "try_take - empty channel", !IO)
+        TakeResult = would_block,
+        log(Log, "try_take - would block (possibly empty)", !IO)
     ).
 
 %---------------------------------------------------------------------------%
-- 
2.25.0



More information about the reviews mailing list