Skip to content

Uninterruptible fibers' bracket handler marked as 'Killed' instead of 'Completed' #174

Open
@felixSchl

Description

@felixSchl
module Test.Main
  ( main
  ) where

import Prelude

import Control.Monad.Fork.Class (BracketCondition(..), bracket, fork, uninterruptible)
import Data.Time.Duration (Milliseconds(..))
import Debug.Trace (traceM)
import Effect (Effect)
import Effect.Aff (delay, killFiber, launchAff_)
import Effect.Class (liftEffect)
import Effect.Class.Console as Console
import Effect.Exception (error)

atomic action postAction =
  bracket (pure unit) (\a b ->
    case a of
      Completed x ->
        postAction
      Failed e ->
        traceM "failed"
      Killed e ->
        traceM "killed"
  ) (\_-> action)

main :: Effect Unit
main = do
 launchAff_ do

   fiber <- fork do
     atomic
      (uninterruptible do
          delay $ 15.0 # Milliseconds
          liftEffect $ Console.log "hi"
      )
      (liftEffect $ Console.log "here")

   delay $ 10.0 # Milliseconds
   killFiber (error "asdf") fiber

The above code only traces "killed", although it should most likely have run the postAction handler, thus printing "here" to the console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions