generated from tpl/purs
fix: share env
This commit is contained in:
parent
1f4995a2d1
commit
6648d349e9
@ -1,5 +1,6 @@
|
|||||||
module Node.Worker.Parent
|
module Node.Worker.Parent
|
||||||
( Worker
|
( Worker
|
||||||
|
, SpawnEnv
|
||||||
, stdout
|
, stdout
|
||||||
, stderr
|
, stderr
|
||||||
, stdin
|
, stdin
|
||||||
@ -33,12 +34,11 @@ import Effect.Aff (Aff)
|
|||||||
import Effect.Exception (Error)
|
import Effect.Exception (Error)
|
||||||
import Effect.Uncurried (mkEffectFn1)
|
import Effect.Uncurried (mkEffectFn1)
|
||||||
import Foreign (Foreign, unsafeToForeign)
|
import Foreign (Foreign, unsafeToForeign)
|
||||||
import Foreign.Object (Object)
|
|
||||||
import Foreign.Object as Object
|
import Foreign.Object as Object
|
||||||
import Node.EventEmitter (EventHandle(..))
|
import Node.EventEmitter (EventHandle(..))
|
||||||
import Node.EventEmitter.UtilTypes (EventHandle1, EventHandle0)
|
import Node.EventEmitter.UtilTypes (EventHandle1, EventHandle0)
|
||||||
import Node.Stream (Readable, Writable)
|
import Node.Stream (Readable, Writable)
|
||||||
import Node.Worker (ResourceLimits)
|
import Node.Worker (ResourceLimits, shareEnv)
|
||||||
import Node.Worker.Port (class PortLike)
|
import Node.Worker.Port (class PortLike)
|
||||||
import Node.Worker.Serializable (class Serializable, deserialize, serialize)
|
import Node.Worker.Serializable (class Serializable, deserialize, serialize)
|
||||||
import Prim.Row (class Nub, class Union)
|
import Prim.Row (class Nub, class Union)
|
||||||
@ -66,7 +66,7 @@ instance PortLike Worker where
|
|||||||
|
|
||||||
type SpawnImplOptions =
|
type SpawnImplOptions =
|
||||||
( argv :: Nullable (Array Foreign)
|
( argv :: Nullable (Array Foreign)
|
||||||
, env :: Nullable (Object String)
|
, env :: Nullable Foreign
|
||||||
, eval :: Nullable (Boolean)
|
, eval :: Nullable (Boolean)
|
||||||
, execArgv :: Nullable (Array String)
|
, execArgv :: Nullable (Array String)
|
||||||
, stdin :: Nullable (Boolean)
|
, stdin :: Nullable (Boolean)
|
||||||
@ -79,9 +79,13 @@ type SpawnImplOptions =
|
|||||||
, name :: Nullable (String)
|
, name :: Nullable (String)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data SpawnEnv
|
||||||
|
= InheritEnv
|
||||||
|
| FixedEnv (Map String String)
|
||||||
|
|
||||||
type SpawnOptions r =
|
type SpawnOptions r =
|
||||||
( argv :: Maybe (Array String)
|
( argv :: Maybe (Array String)
|
||||||
, env :: Maybe (Map String String)
|
, env :: Maybe SpawnEnv
|
||||||
, execArgv :: Maybe (Array String)
|
, execArgv :: Maybe (Array String)
|
||||||
, stdin :: Maybe (Boolean)
|
, stdin :: Maybe (Boolean)
|
||||||
, stdout :: Maybe (Boolean)
|
, stdout :: Maybe (Boolean)
|
||||||
@ -108,20 +112,26 @@ emptySpawnOptions =
|
|||||||
}
|
}
|
||||||
|
|
||||||
spawnOptionsToImpl :: forall a. Serializable a => Record (SpawnOptions (workerData :: Maybe a, eval :: Boolean)) -> Record SpawnImplOptions
|
spawnOptionsToImpl :: forall a. Serializable a => Record (SpawnOptions (workerData :: Maybe a, eval :: Boolean)) -> Record SpawnImplOptions
|
||||||
spawnOptionsToImpl = applyRecord
|
spawnOptionsToImpl =
|
||||||
{ argv: Nullable.toNullable <<< map (map unsafeToForeign)
|
let
|
||||||
, env: Nullable.toNullable <<< map Object.fromFoldableWithIndex
|
mapEnv (Just InheritEnv) = Nullable.notNull $ unsafeToForeign shareEnv
|
||||||
, eval: Nullable.notNull
|
mapEnv (Just (FixedEnv env)) = Nullable.notNull $ serialize $ Object.fromFoldableWithIndex env
|
||||||
, execArgv: Nullable.toNullable
|
mapEnv Nothing = Nullable.null
|
||||||
, stdin: Nullable.toNullable
|
in
|
||||||
, stdout: Nullable.toNullable
|
applyRecord
|
||||||
, stderr: Nullable.toNullable
|
{ argv: Nullable.toNullable <<< map (map unsafeToForeign)
|
||||||
, trackUnmanagedFds: Nullable.toNullable
|
, env: mapEnv
|
||||||
, transferList: Nullable.toNullable
|
, eval: Nullable.notNull
|
||||||
, resourceLimits: Nullable.toNullable
|
, execArgv: Nullable.toNullable
|
||||||
, name: Nullable.toNullable
|
, stdin: Nullable.toNullable
|
||||||
, workerData: Nullable.toNullable <<< map serialize
|
, stdout: Nullable.toNullable
|
||||||
}
|
, stderr: Nullable.toNullable
|
||||||
|
, trackUnmanagedFds: Nullable.toNullable
|
||||||
|
, transferList: Nullable.toNullable
|
||||||
|
, resourceLimits: Nullable.toNullable
|
||||||
|
, name: Nullable.toNullable
|
||||||
|
, workerData: Nullable.toNullable <<< map serialize
|
||||||
|
}
|
||||||
|
|
||||||
spawnFile :: forall a r optsdup. Serializable a => Union r (SpawnOptions ()) optsdup => Nub optsdup (SpawnOptions ()) => Record r -> String -> a -> Effect Worker
|
spawnFile :: forall a r optsdup. Serializable a => Union r (SpawnOptions ()) optsdup => Nub optsdup (SpawnOptions ()) => Record r -> String -> a -> Effect Worker
|
||||||
spawnFile opts' file d =
|
spawnFile opts' file d =
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Node.Worker (ResourceLimits, resourceLimits, isMainThread, threadId, markUntransferable) where
|
module Node.Worker (ResourceLimits, shareEnv, resourceLimits, isMainThread, threadId, markUntransferable) where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user