Ticket #4535 (closed proposal: invalid)

Opened 2 years ago

Last modified 2 years ago

Add tryReadChan to Chan

Reported by: mitar Owned by:
Priority: normal Milestone: Not GHC
Component: libraries/base Version: 7.1
Keywords: Cc: mmitar@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Now that isEmptyChan is deprecated (#4154) it would be useful to add tryReadChan. It seems it is possible to define it so that it does not block like isEmptyChan. This is because semantics is a bit different: tryReadChan is allowed to return Nothing also when Chan is non-empty, but it would block. Contrary, isEmptyChan is expected that it would return False only if Chan is really empty.

I have defined also two new MVar functions which helped me implementing tryReadChan: tryReadMVar and tryModifyMVar. Probably it would be useful to make them public.

Please comment. I propose three weeks for discussion.

Attachments

try-read-chan.patch Download (2.5 KB) - added by mitar 2 years ago.

Change History

Changed 2 years ago by mitar

  Changed 2 years ago by mitar

I am sorry that patch is not in darcs format.

follow-up: ↓ 3   Changed 2 years ago by simonmar

tryReadChan itself looks ok to me.

If tryModifyMVar were to be public, I'd expect its type to be

tryModifyMVar :: MVar a -> (a -> IO (a, b)) -> IO (Maybe b)

but I can see why you used instead

tryModifyMVar :: MVar a -> (a -> IO (a, Maybe b)) -> IO (Maybe b)

because the former would require an extra Control.Monad.join, whereas the latter has it "built-in".

tryReadMVar looks like the right thing, I wouldn't object to that going in Control.Concurrent.MVar.

What is the purpose of the INLINE pragma?

in reply to: ↑ 2   Changed 2 years ago by mitar

Replying to simonmar:

What is the purpose of the INLINE pragma?

I just copied it from modifyMVar. I am not sure if it is needed.

  Changed 2 years ago by igloo

  • milestone set to Not GHC

  Changed 2 years ago by igloo

  • status changed from new to closed
  • resolution set to invalid

Proposal tickets are no longer needed as part of the library submissions process. Instead, a normal ticket should be created once consensus has been achieved. Please see the  process description for details.

Note: See TracTickets for help on using tickets.