-- | Module: Lifetimes.Async
-- Description: Lifteimes integration for the async package.
module Lifetimes.Async (acquireAsync) where

import Control.Concurrent.Async (Async, async, cancel, wait)
import Lifetimes
import Zhp

-- | Spawn an async task. When it is time to reclaim the resource, 'cancel'
-- will be called.
acquireAsync :: IO a -> Acquire (Async a)
acquireAsync :: forall a. IO a -> Acquire (Async a)
acquireAsync IO a
io = forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire (forall a. IO a -> IO (Async a)
async IO a
io) forall a. Async a -> IO ()
cancel