forked from unisonweb/unison
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added skeleton code for
ProcessPool
provide by Paul (here:
unisonweb#24) with some minor changes to make it compile.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters