Skip to content

Instantly share code, notes, and snippets.

@exarkun
Created December 11, 2020 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exarkun/e1b0c67e409c3223206d60256fe31b5e to your computer and use it in GitHub Desktop.
Save exarkun/e1b0c67e409c3223206d60256fe31b5e to your computer and use it in GitHub Desktop.
yieldFirst :: MVar o -> MVar o -> ConduitT () o IO ()
yieldFirst left right = do
repeatMC $ winner left right >>= return . unwrap
return ()
where
winner :: MVar o -> MVar o -> IO (Either o o)
winner left right = race (takeMVar left) (takeMVar right)
unwrap :: Either o o -> o
unwrap (Left o) = o
unwrap (Right o) = o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment