Skip to content

Commit

Permalink
Added skeleton code for ProcessPool provide by Paul (here:
Browse files Browse the repository at this point in the history
unisonweb#24) with some minor changes to
make it compile.
  • Loading branch information
tmciver committed Jun 9, 2016
1 parent c219f40 commit 2374367
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions node/src/Unison/Runtime/ProcessPool.hs
@@ -0,0 +1,29 @@
module Unison.Runtime.ProcessPool where

import Data.Bytes.Serial
import System.Process (ProcessHandle)

newtype TimeBudget = Seconds Int
newtype SpaceBudget = Megabytes Int
type Budget = (TimeBudget, SpaceBudget)
newtype MaxProcesses = MaxProcesses Int
data Err = TimeExceeded | SpaceExceeded | Killed | InsufficientProcesses
type ID = Int

data Pool a b = Pool {
-- | Evaluate the thunk in a separate process, with the given budget.
-- If there is no available process for that `Budget`, create a new one,
-- unless that would exceed the `MaxProcesses` bound, in which case
-- fail fast with `Left InsufficientProcesses`.
evaluate :: Budget -> MaxProcesses -> ID -> a -> IO (Either Err b),

-- | Forcibly kill the process associated with an ID. Any prior `evaluate` for
-- that `ID` should complete with `Left Killed`.
kill :: ID -> IO (),

-- | Shutdown the entire pool. After this completes, no other processes should be running
shutdown :: IO ()
}

pool :: (Serial a, Serial b) => IO ProcessHandle -> IO (Pool a b)
pool createWorker = undefined
9 changes: 9 additions & 0 deletions node/src/Unison/Runtime/Worker.hs
@@ -0,0 +1,9 @@
module Unison.Runtime.Worker where

import Data.Bytes.Serial

worker :: (Serial a, Serial b) => (a -> IO b) -> IO ()
worker eval = undefined

main :: IO ()
main = undefined
3 changes: 3 additions & 0 deletions node/unison-node.cabal
Expand Up @@ -63,6 +63,8 @@ library
Unison.Runtime.Unfold
Unison.Runtime.Vector
Unison.Runtime.ResourcePool
Unison.Runtime.ProcessPool
Unison.Runtime.Worker

build-depends:
aeson,
Expand All @@ -86,6 +88,7 @@ library
network,
network-simple,
prelude-extras,
process,
scotty,
sockaddr,
stm,
Expand Down

0 comments on commit 2374367

Please sign in to comment.