• how to wait for the parallel job finish

    From meInvent bbird@21:1/5 to All on Fri Jul 29 20:55:40 2016
    data Async a = Async (MVar a)

    async :: IO a -> IO (Async a)
    async action = do
    var <- newEmptyMVar
    forkIO (do r <- action; putMVar var r)
    return (Async var)

    wait :: Async a -> IO a
    wait (Async var) = readMVar var

    main = do
    --forM_ [0..((length getoperationlist)-1)] maxmagic
    as <- forM_ (async . [0..((length getoperationlist)-1)]) maxmagic
    forM_ wait as

    trees2aParallel.hs:132:26:
    Couldn't match expected type ‘[Int]’
    with actual type ‘a3 -> IO (Async a4)’
    In the first argument of ‘forM_’, namely
    ‘(async . [0 .. ((length getoperationlist) - 1)])’
    In a stmt of a 'do' block:
    as <- forM_
    (async . [0 .. ((length getoperationlist) - 1)]) maxmagic
    In the expression:
    do { let input1 = input2 5;
    let oplist = filter isSorted input1;
    let getoperationlist = ...;
    let fullytruerownum = 27;
    .... }

    trees2aParallel.hs:132:34:
    Couldn't match expected type ‘a3 -> IO a4’ with actual type ‘[Int]’
    In the second argument of ‘(.)’, namely
    ‘[0 .. ((length getoperationlist) - 1)]’
    In the first argument of ‘forM_’, namely
    ‘(async . [0 .. ((length getoperationlist) - 1)])’
    In a stmt of a 'do' block:
    as <- forM_
    (async . [0 .. ((length getoperationlist) - 1)]) maxmagic

    trees2aParallel.hs:133:19:
    Couldn't match expected type ‘[a5]’
    with actual type ‘Async a6 -> IO a6’
    Probable cause: ‘wait’ is applied to too few arguments
    In the first argument of ‘forM_’, namely ‘wait’
    In a stmt of a 'do' block: forM_ wait as

    trees2aParallel.hs:133:24:
    Couldn't match expected type ‘a5 -> IO b1’ with actual type ‘()’
    In the second argument of ‘forM_’, namely ‘as’
    In a stmt of a 'do' block: forM_ wait as

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)