Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,268
    • Issues 4,268
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 408
    • Merge Requests 408
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8850

Closed
Open
Opened Mar 05, 2014 by bholst@trac-bholst

(Compositional) function mkWeakChan

Following the existing functions mkWeakIORef and mkWeakMVar, I'd like to have a function mkWeakChan with the following type signature, similar to that of mkWeakMVar requested by ticket #7285:

mkWeakChan :: Chan a -> v -> Maybe (IO ()) -> IO (Weak v)

The implementation of Chan is private, so it is not easily possible to implement it yourself. The implementation of both functions may look like the following:

mkWeakMVar :: MVar a -> v -> Maybe (IO ()) -> IO (Weak v)
mkWeakMVar (MVar m#) v (Just f) = IO $ \s ->
  case mkWeak# m# v f s of (# s1, w #) -> (# s1, Weak w #)
mkWeakMVar (MVar m#) v Nothing  = IO $ \s ->
  case mkWeakNoFinalizer# m# v s of { (# s1, w #) -> (# s1, Weak w #) }

mkWeakChan :: Chan a -> v -> Maybe (IO ()) -> IO (Weak v)
mkWeakChan c@(Chan readVar writeVar) v f = do
  _ <- mkWeakMVar readVar  writeVar Nothing
  mkWeakMVar writeVar v f
Trac metadata
Trac field Value
Version 7.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related #7285
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8850