úÎirfQ'      !"#$%&#non-portable (requires concurrency) provisional!Simon Marlow <marlowsd@gmail.com> Trustworthy&A value of type Concurrently a is an IO operation that can be  composed with other  Concurrently values, using the  Applicative  and  Alternative instances. Calling runConcurrently on a value of type Concurrently a will  execute the IO- operations it contains concurrently, before  delivering the result of type a.  For example  (page1, page2, page3)  <- runConcurrently $ (,,) & <$> Concurrently (getURL "url1") & <*> Concurrently (getURL "url2") & <*> Concurrently (getURL "url3") "An asynchronous action spawned by  or  . = Asynchronous actions are executed in a separate thread, and A operations are provided for waiting for asynchronous actions to 0 complete and obtaining their results (see e.g. ).  Returns the '! of the thread running the given . 3Spawn an asynchronous action in a separate thread. Like  but using ( internally. Like  but using ) internally. Like  but using * internally. [ The child thread is passed a function that can be used to unmask asynchronous exceptions. Like  but using + internally. [ The child thread is passed a function that can be used to unmask asynchronous exceptions. @Spawn an asynchronous action in a separate thread, and pass its  Async= handle to the supplied function. When the function returns  or throws an exception,  is called on the Async.  > withAsync action inner = bracket (async action) cancel inner This is a useful variant of  that ensures an Async is % never left running unintentionally. Since  may block,   may also block; see   for details. Like   but uses ( internally. Like   but uses ) internally. Like   but uses * internally. [ The child thread is passed a function that can be used to unmask asynchronous exceptions. Like   but uses + internally. Z The child thread is passed a function that can be used to unmask asynchronous exceptions <Wait for an asynchronous action to complete, and return its A value. If the asynchronous action threw an exception, then the  exception is re-thrown by .  wait = atomically . waitSTM ?Wait for an asynchronous action to complete, and return either  Left e# if the action raised an exception e, or Right a if it  returned a value a. ' waitCatch = atomically . waitCatchSTM Check whether an # has completed yet. If it has not # completed yet, then the result is Nothing, otherwise the result  is Just e where e is Left x if the Async raised an  exception x, or Right a if it returned a value a.  poll = atomically . pollSTM  A version of - that can be used inside an STM transaction.  A version of - that can be used inside an STM transaction.  A version of - that can be used inside an STM transaction. .Cancel an asynchronous action by throwing the  ThreadKilled ( exception to it. Has no effect if the  has already  completed.  3 cancel a = throwTo (asyncThreadId a) ThreadKilled  Note that % is synchronous in the same sense as ,. ? It does not return until the exception has been thrown in the D target thread, or the target thread has completed. In particular, C if the target thread is making a foreign call, the exception will @ not be thrown until the foreign call returns, and in this case  * may block indefinitely. An asynchronous  can # of course be obtained by wrapping  itself in . ACancel an asynchronous action by throwing the supplied exception  to it.  . cancelWith a x = throwTo (asyncThreadId a) x *The notes about the synchronous nature of  also apply to  . BWait for any of the supplied asynchronous operations to complete. % The value returned is a pair of the  that completed, and the " result that would be returned by  on that .  If multiple -s complete or have completed, then the value - returned corresponds to the first completed  in the list. Like *, but also cancels the other asynchronous * operations as soon as one has completed. Wait for any of the supplied Asyncs to complete. If the first C to complete throws an exception, then that exception is re-thrown  by .  If multiple -s complete or have completed, then the value - returned corresponds to the first completed  in the list. Like *, but also cancels the other asynchronous * operations as soon as one has completed. Wait for the first of two Async s to finish. Like  , but also s both Async s before  returning. Wait for the first of two Asyncs to finish. If the Async @ that finished first raised an exception, then the exception is  re-thrown by . Like , but the result is ignored. Like  , but also s both Async s before  returning. Waits for both Async*s to finish, but if either of them throws D an exception before they have both finished, then the exception is  re-thrown by  . !Link the given Async) to the current thread, such that if the  Async: raises an exception, that exception will be re-thrown in  the current thread. " Link two Async*s together, such that if either raises an 9 exception, the same exception is re-thrown in the other Async. #Run two IO/ actions concurrently, and return the first to # finish. The loser of the race is led.  race left right =  withAsync left $ \a ->  withAsync right $ \b ->  waitEither a b $Like #, but the result is ignored. %Run two IO4 actions concurrently, and return both results. If ? either action throws an exception at any time, then the other  action is 'led, and the exception is re-thrown by  %.  concurrently left right =  withAsync left $ \a ->  withAsync right $ \b ->  waitBoth a b &maps an IO-performing function over any  Traversable data  type, performing all the IO% actions concurrently, and returning @ the original data structure with the arguments replaced by the  results.  For example, mapConcurrently works with lists: : pages <- mapConcurrently getURL ["url1", "url2", "url3"] -AFork a thread that runs the supplied action, and if it raises an E exception, re-runs the action. The thread terminates only when the 9 action runs to completion without raising an exception. 7./ 0 1 !"#$%2&-3456789:;<'  !"#$%&(  !"#$%&2./ 0 1 !"#$%2&-3456789:;<=      !"#$%&'()*(+,()-().()/()0123456789:;<=>?@ async-2.0.1.4Control.Concurrent.Async ConcurrentlyrunConcurrentlyAsync asyncThreadIdasync asyncBoundasyncOnasyncWithUnmaskasyncOnWithUnmask withAsyncwithAsyncBound withAsyncOnwithAsyncWithUnmaskwithAsyncOnWithUnmaskwait waitCatchpollwaitSTM waitCatchSTMpollSTMcancel cancelWith waitAnyCatchwaitAnyCatchCancelwaitAny waitAnyCancelwaitEitherCatchwaitEitherCatchCancel waitEither waitEither_waitEitherCancelwaitBothlinklink2racerace_ concurrentlymapConcurrentlybase GHC.Conc.SyncThreadIdControl.ConcurrentforkOSforkOnforkIOWithUnmaskforkOnWithUnmaskthrowTo forkRepeat _asyncWait asyncUsingwithAsyncUsing concurrently'catchAlltryAll rawForkIO rawForkOn$fAlternativeConcurrently$fApplicativeConcurrently$fFunctorConcurrently$fFunctorAsync $fOrdAsync $fEqAsync