Ԙ=      !"#$%&'()*+,-./0123456789:;<(c) Simon Marlow 2012BSD3 (see the file LICENSE)!Simon Marlow <marlowsd@gmail.com> provisional#non-portable (requires concurrency) Trustworthy%&BOT-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 IOL 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 operations are provided for waiting for asynchronous actions to complete and obtaining their results (see e.g. ).=4The number of available execution slots in the pool.>2Nodes in the task graph that are waiting to start.A 5 manages a collection of possibly interdependent tasks, such that tasks await execution until the tasks they depend on have finished (and tasks may depend on an arbitrary number of other tasks), while independent tasks execute concurrently up to the number of available resource slots in the pool.Results from each task are available until the status of the task is polled or waited on. Further, the results are kept until that occurs, so failing to ever wait will result in a memory leak.MTasks may be cancelled, in which case all dependent tasks are unscheduled.?The task graph represents a partially ordered set P with subset S such that for every x " S and y " P, either x "d y or x is unrelated to y. Stated more simply, S is the set of least elements of all maximal chains in P. In our case, "d relates two uncompleted tasks by dependency. Therefore, S is equal to the set of tasks which may execute concurrently, as none of them have incomplete dependencies.We use a graph representation to make determination of S more efficient (where S is just the set of roots in P expressed as a graph). Completion status is recorded on the edges, and nodes are removed from the graph once no other incomplete node depends on them.@9Tokens identify tasks, and are provisioned monotonically.AA A2 is a unique identifier for a task submitted to a .2Spawn an asynchronous action in a separate thread.Like  but using B internally. Like  but using C internally. Like  but using Dg internally. The child thread is passed a function that can be used to unmask asynchronous exceptions. Like   but using Eg internally. The child thread is passed a function that can be used to unmask asynchronous exceptions.FkReturn the next available thread identifier from the pool. These are monotonically increasing integers. ASpawn an asynchronous action in a separate thread, and pass its AsyncV 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 innerThis 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 B internally.Like   but uses C internally.Like   but uses Dg internally. The child thread is passed a function that can be used to unmask asynchronous exceptions.Like  but uses Ef internally. The child thread is passed a function that can be used to unmask asynchronous exceptionsWait for an asynchronous action to complete, and return its 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 . waitCatchSTMCheck whether an F 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. 1cancel a = throwTo (asyncThreadId a) ThreadKilled Note that % is synchronous in the same sense as G . It does not return until the exception has been thrown in the target thread, or the target thread has completed. In particular, 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 .HHCancel 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 .I.Cancel an asynchronous action by throwing the  ThreadKilledp exception to it, or unregistering it from the task pool if it had not started yet. Has no effect if the  has already completed. Note that % is synchronous in the same sense as G . It does not return until the exception has been thrown in the target thread, or the target thread has completed. In particular, 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 .gWait 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 Zs complete or have completed, then the value returned corresponds to the first completed  in the list.Like S, but also cancels the other asynchronous operations as soon as one has completed.Wait for any of the supplied Asyncds to complete. If the first to complete throws an exception, then that exception is re-thrown by . If multiple Zs complete or have completed, then the value returned corresponds to the first completed  in the list.Like S, 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 Asyncs before returning.Wait for the first of two Asyncs to finish. If the AsyncO that finished first raised an exception, then the exception is re-thrown by . Like , but the result is ignored.!Like  , but also s both Asyncs before returning."Waits for both Async|s to finish, but if either of them throws 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 AsyncN raises an exception, that exception will be re-thrown in the current thread.$ Link two Asynccs together, such that if either raises an exception, the same exception is re-thrown in the other Async.%Run two IOR actions concurrently, and return the first to finish. The loser of the race is led. Urace left right = withAsync left $ \a -> withAsync right $ \b -> waitEither a b&Like %, but the result is ignored.'Run two IO~ 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 IOn actions concurrently, and returning the original data structure with the arguments replaced by the results. For example, mapConcurrently works with lists: 8pages <- mapConcurrently getURL ["url1", "url2", "url3"]JFork a thread that runs the supplied action, and if it raises an exception, re-runs the action. The thread terminates only when the action runs to completion without raising an exception.SKLMNO=>P?@QRSTUVWXAYZ[\ ]F^ _HI !"#$%&'(J`abcdefghijklmnopqrstuvwxyz{|}~KMLNO=>P?@QRSTUVWXAYZ[\ ]F^ _HI !"#$%&'(J`abcAKLMNO=>P?@QRSTUVWXAYZ[\ ]F^ _HI !"#$%&'(J`abcdefghijkNone:OT)The ) Applicative and Monad allow for task dependencies to be built using Applicative and do notation. Monadic evaluation is sequenced, while applicative Evaluation is concurrent for each argument. In this way, mixing the two builds a dependency graph via ordinary Haskell code.qReturn a list of actions ready for execution, by checking the graph to ensure all dependencies have completed.hReturn a list of tasks ready to execute, and their related state variables from the dependency graph.*QCreate a task pool for managing many-to-many acyclic dependencies among tasks.AUse a task pool for a bounded region. At the end of the region, + will block until all tasks have completed.+Create a task group for executing interdependent tasks concurrently. The number of available slots governs how many tasks may run at one time.,rExecute tasks in a given task group. The number of slots determines how many threads may execute concurrently.-Create a task group within the given pool having a specified number of execution slots, but with a bounded lifetime. Leaving the block cancels every task still executing in the group..LCreate both a pool, and a task group with a given number of execution slots./eGiven parent and child tasks, link them so the child cannot execute until the parent has finished.0Given parent and child tasks, link them so the child cannot execute until the parent has finished. This function does not check for introduction of cycles into the dependency graph, which would prevent the child from ever running.1Equivalent to , but acts in STM so that /L may be called after the task is created, but before it begins executing.2Submit a task which begins execution after all its parents have completed. This is equivalent to submitting a new task with 1= and linking it to its parents using 'mapM makeDependent'.3}Submit a task that begins execution only after its parent has completed. This is equivalent to submitting a new task with 1' and linking it to its parent using /.3Helper function used by several of the variants of 4 below.4Execute a group of tasks within the given task group, returning the results in order. The order of execution is random, but the results are returned in order.5Execute a group of tasks within the given task group, returning the results in order as an Either type to represent exceptions from actions. The order of execution is random, but the results are returned in order.6GExecute a group of tasks within the given task group, ignoring results.7rExecute a group of tasks within the given task group, ignoring results, but returning a list of all exceptions.8cExecute a group of tasks, but return the first result or failure and cancel the remaining tasks.9!Given a list of actions yielding a results, execute the actions concurrently (up to N at a time, based on available slots), and l each pair of results concurrently as they become ready. The immediate result of this function is an  representing the final value."This is similar to the following: mconcat  $ mapTasks n actions, except that intermediate results can be garbage collected as soon as they've been merged. Also, the value returned from this function is an * which may be polled for the final result.Lastly, if an  Exception occurs in any subtask, the final result will also yield an exception -- but not necessarily the first or last that was caught.:YExecute a group of tasks concurrently (using up to N active threads, depending on the task group), and feed results to a continuation as soon as they become available, in random order. The continuation function may return a monoid value which is accumulated to yield a final result. If no such value is needed, simply provide `()`.;Run a value in the )7 monad and block until the final result is computed.< Lift any  action into a ). This is a synonym for .)*+,-./ Handle of task doing the waiting+Handle of task we must wait on (the parent)0 Handle of task doing the waiting+Handle of task we must wait on (the parent)123456789&Task group to execute the tasks within!Set of Monoid-yielding IO actionsReturns the final result task:;<)*+,-./0123456789:;<)*+,-./0123456789:;<((c) Simon Marlow 2012, John Wiegley 2014BSD3 (see the file LICENSE)$John Wiegley <johnw@newartisans.com> provisional#non-portable (requires concurrency)None=  !"#$%&'()*+,-./0123456789:;<>.-*+, 132/0 ! "#$465789:);<%&'(      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGEHIEHJEHKLEHMNOPQRS TUVWXYZ[\]^_`abcdefghijklmnopqopropsoptopuopvopwopxopyopzop{op|o}~o}ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooEEE,)async-pool-0.9.0.2-1uS5P5ETyxU3MWb4ahInb1Control.Concurrent.Async.Pool#Control.Concurrent.Async.Pool.Async&Control.Concurrent.Async.Pool.Internal ConcurrentlyrunConcurrentlyAsync taskHandle TaskGroupPoolasync asyncBoundasyncOnasyncWithUnmaskasyncOnWithUnmask withAsyncwithAsyncBound withAsyncOnwithAsyncWithUnmaskwithAsyncOnWithUnmaskwait waitCatchpollwaitSTM waitCatchSTMpollSTMcancel cancelWith waitAnyCatchwaitAnyCatchCancelwaitAny waitAnyCancelwaitEitherCatchwaitEitherCatchCancel waitEither waitEither_waitEitherCancelwaitBothlinklink2racerace_ concurrentlymapConcurrentlyTask createPoolcreateTaskGroup runTaskGroupwithTaskGroupIn withTaskGroup makeDependentunsafeMakeDependentasyncSTM asyncAfterAll asyncAftermapTasks mapTasksE mapTasks_ mapTasksE_mapRace mapReducescatterFoldMapMrunTasktaskavailpendingtaskstokensHandlebaseControl.ConcurrentforkOS GHC.Conc.SyncforkOnforkIOWithUnmaskforkOnWithUnmask nextIdentthrowTo cancelWith' cancelAll forkRepeat taskGroup _asyncWaitpool TaskGraphStatusPending CompletedStateReadyStartingStarted waitTMVarsyncPool getTaskVar getThreadId asyncUsing cleanupTaskwithAsyncUsingcatchAlltryAll rawForkIO rawForkOn$fAlternativeConcurrently$fApplicativeConcurrently$fFunctorConcurrently$fFunctorAsync $fOrdAsync $fEqAsync $fShowState $fEqState!fgl-5.6.0.0-k2vM7sbvmd5KrlOuk9qGpData.Graph.Inductive.Query.BFSlesplbftespbftbfebfenlevelnlevelbfsbfsWithbfsnbfsnWith!Data.Graph.Inductive.PatriciaTreeGrUGr&Data.Graph.Inductive.Internal.RootPathRTreeData.Graph.Inductive.Graph prettyPrintprettifyequalhasNeighborAdjhasLEdge hasNeighborhasEdgedeg'indeg'outdeg'inn'out'lpre'lsuc'pre'suc' lneighbors' neighbors'labNode'lab'node'degindegoutdeginnoutlprelsucpresuc lneighbors neighborslabcontextsubgraph labfilternfilter labnfilter gfiltermapmkUGraphbuildGrdelEdgesdelNodesinsEdgesinsNodes delAllLEdgedelLEdgedelEdgedelNodeinsEdgeinsNodegelemnewNodes edgeLabeltoLEdgetoEdgeedgesnodesnemapemapnmapgmapufoldsizeorderNodeLNodeUNodeEdgeLEdgeUEdgePathLPathLPunLPathUPathAdjContextMContextDecompGDecompUContextUDecompGraphmatchemptyisEmptymkGraphlabNodesmatchAnynoNodes nodeRangelabEdgesDynGraphOrdGrunOrdGr getReadyNodes getReadyTaskswithPoolmapTasksWorkerGHC.BaseMonoidmappendghc-prim GHC.TypesIOControl.Monad.IO.ClassliftIOrunTask' $fMonadIOTask $fMonadTask$fApplicativeTask $fFunctorTask