Documentation
¶
Index ¶
- Constants
- Variables
- func SetWriteSync(stdoutWriters, stderrWriters []MsgWriter)
- type MessagePoster
- type MsgWriter
- type SelfConn
- func (s *SelfConn) Close() error
- func (s *SelfConn) Name() (string, error)
- func (s *SelfConn) NewMsgWriterToControllerStderr() MsgWriter
- func (s *SelfConn) NewMsgWriterToControllerStdout() MsgWriter
- func (s *SelfConn) PostMessage(message safejs.Value, transfers []safejs.Value) error
- func (s *SelfConn) ResetWriteSync()
- func (s *SelfConn) SetupConn() (_ <-chan types.MessageEventMessage, err error)
- type SelfSharedConn
- func (s *SelfSharedConn) Close() error
- func (s *SelfSharedConn) Idle() bool
- func (s *SelfSharedConn) Location() (*types.WorkerLocation, error)
- func (s *SelfSharedConn) Name() (string, error)
- func (s *SelfSharedConn) NewMsgWriterToControllerStderr() MsgWriter
- func (s *SelfSharedConn) NewMsgWriterToControllerStdout() MsgWriter
- func (s *SelfSharedConn) ResetWriteSync()
- func (s *SelfSharedConn) SetupConn() (_ <-chan *SelfSharedConnPort, err error)
- type SelfSharedConnPort
- type WasmSharedWebWorker
- func (ww *WasmSharedWebWorker) Close() error
- func (ww *WasmSharedWebWorker) Connect() error
- func (ww *WasmSharedWebWorker) Listen(ctx context.Context) (<-chan types.MessageEventMessage, error)
- func (ww *WasmSharedWebWorker) PostMessage(data safejs.Value, transfers []safejs.Value) error
- func (ww *WasmSharedWebWorker) Start() error
- type WasmSharedWebWorkerConn
- func (conn *WasmSharedWebWorkerConn) Close() error
- func (conn *WasmSharedWebWorkerConn) Connect() (err error)
- func (conn *WasmSharedWebWorkerConn) EventChannel() <-chan types.MessageEventMessage
- func (conn *WasmSharedWebWorkerConn) PostMessage(data safejs.Value, transfers []safejs.Value) error
- func (conn *WasmSharedWebWorkerConn) Start() (*WasmSharedWebWorkerMgmtConn, error)
- func (conn *WasmSharedWebWorkerConn) Wait()
- type WasmSharedWebWorkerMgmtConn
- func (c *WasmSharedWebWorkerMgmtConn) Close() error
- func (c *WasmSharedWebWorkerMgmtConn) Connect() (conn *WasmSharedWebWorkerConn, err error)
- func (c *WasmSharedWebWorkerMgmtConn) SetWriteToConsole() error
- func (c *WasmSharedWebWorkerMgmtConn) SetWriteToController() error
- func (c *WasmSharedWebWorkerMgmtConn) Stderr() io.ReadCloser
- func (c *WasmSharedWebWorkerMgmtConn) Stdout() io.ReadCloser
- func (c *WasmSharedWebWorkerMgmtConn) Wait()
- type WasmWebWorker
- type WasmWebWorkerConn
- func (conn *WasmWebWorkerConn) EventChannel() <-chan types.MessageEventMessage
- func (conn *WasmWebWorkerConn) PostMessage(data safejs.Value, transfers []safejs.Value) error
- func (conn *WasmWebWorkerConn) Start() (err error)
- func (conn *WasmWebWorkerConn) StderrPipe() (io.ReadCloser, error)
- func (conn *WasmWebWorkerConn) StdoutPipe() (io.ReadCloser, error)
- func (conn *WasmWebWorkerConn) Terminate()
- func (conn *WasmWebWorkerConn) Wait()
- type WebWorkerCloseFunc
Constants ¶
const CLOSE_EVENT = "__WASMWW_CLOSE__"
const STDERR_EVENT = "__WASMWW_STDERR__"
const STDOUT_EVENT = "__WASMWW_STDOUT__"
const WRITE_TO_CONSOLE_EVENT = "__WASMWW_WRITE_TO_CONSOLE__"
const WRITE_TO_CONTROLLER_EVENT = "__WASMWW_WRITE_TO_CONTROLLER"
Variables ¶
var WorkerJSTpl []byte
Functions ¶
func SetWriteSync ¶
func SetWriteSync(stdoutWriters, stderrWriters []MsgWriter)
SetWriteSync overrides the "writeSync" implementation that will be called by Go. It redirects the message to a slice of `MsgWriterFunc` functions for both the stdout and stderr.
Types ¶
type MessagePoster ¶
type MsgWriter ¶
type MsgWriter interface { Write(p []byte) (n int, err error) // contains filtered or unexported methods }
func NewMsgWriterToConsole ¶
func NewMsgWriterToConsole() MsgWriter
func NewMsgWriterToIoWriter ¶
type SelfConn ¶
type SelfConn struct {
// contains filtered or unexported fields
}
func NewSelfConn ¶
func (*SelfConn) Close ¶
Close closes the web worker, and close the event channel on the controller side.
func (*SelfConn) NewMsgWriterToControllerStderr ¶
func (*SelfConn) NewMsgWriterToControllerStdout ¶
func (*SelfConn) PostMessage ¶
func (*SelfConn) ResetWriteSync ¶
func (s *SelfConn) ResetWriteSync()
func (*SelfConn) SetupConn ¶
func (s *SelfConn) SetupConn() (_ <-chan types.MessageEventMessage, err error)
SetupConn setup the worker for working with the peering WasmWebWorkerConn. The returned eventCh receives the event sent from the peering WasmWebWorkerConn, until the closeFn is called. The closeFn is used to instruct the peering to stop listening to this web worker, and close this web worker.
type SelfSharedConn ¶
type SelfSharedConn struct {
// contains filtered or unexported fields
}
func NewSelfSharedConn ¶
func NewSelfSharedConn() (*SelfSharedConn, error)
func (*SelfSharedConn) Close ¶
func (s *SelfSharedConn) Close() error
Close closes the web worker, and close the event channels on all the controllers side.
func (*SelfSharedConn) Idle ¶
func (s *SelfSharedConn) Idle() bool
Idle tells whether this Shared Web Worker has no connected port at this point
func (*SelfSharedConn) Location ¶
func (s *SelfSharedConn) Location() (*types.WorkerLocation, error)
func (*SelfSharedConn) Name ¶
func (s *SelfSharedConn) Name() (string, error)
func (*SelfSharedConn) NewMsgWriterToControllerStderr ¶
func (s *SelfSharedConn) NewMsgWriterToControllerStderr() MsgWriter
func (*SelfSharedConn) NewMsgWriterToControllerStdout ¶
func (s *SelfSharedConn) NewMsgWriterToControllerStdout() MsgWriter
func (*SelfSharedConn) ResetWriteSync ¶
func (s *SelfSharedConn) ResetWriteSync()
func (*SelfSharedConn) SetupConn ¶
func (s *SelfSharedConn) SetupConn() (_ <-chan *SelfSharedConnPort, err error)
SetupConn set up the worker for working with the peering WasmSharedWebWorkerConn. The returned eventCh sends the SelfSharedConnPort connected with the peering WasmSharedWebWorkerConn, until the closeFn is called.
type SelfSharedConnPort ¶
type SelfSharedConnPort struct {
// contains filtered or unexported fields
}
func (*SelfSharedConnPort) Close ¶
func (p *SelfSharedConnPort) Close() error
Close closes this port, and close the event channel on the controller side.
func (*SelfSharedConnPort) PostMessage ¶
func (*SelfSharedConnPort) SetupConn ¶
func (p *SelfSharedConnPort) SetupConn() (_ <-chan types.MessageEventMessage, err error)
SetupConn set up the worker port for working with the peering WasmSharedWebWorkerConn. The returned eventCh sends the MessageEvent connected with the peering WasmSharedWebWorkerConn, until the closeFn is called.
type WasmSharedWebWorker ¶
type WasmSharedWebWorker struct { // If this is not specified, `Start` will create a UUIDv4 for it and populate back. // // This is required in the Connect(). Name string // This can be a relative path on the server, or an abosolute URL. // // This is ignored in the Connect(). Path string // If the Args field is empty or nil, Run uses {Path}. // // This is ignored in the Connect(). Args []string // Each entry is of the form "key=value". // If Env is nil, the new Web Worker uses the current context's // environment. // If Env contains duplicate environment keys, only the last // value in the slice for each duplicate key is used. // // This is ignored in the Connect(). Env []string // This is filled in in the Start(), and is required in the Connect(). URL string // contains filtered or unexported fields }
func (*WasmSharedWebWorker) Close ¶
func (ww *WasmSharedWebWorker) Close() error
Close closes the message port of this worker.
func (*WasmSharedWebWorker) Connect ¶
func (ww *WasmSharedWebWorker) Connect() error
func (*WasmSharedWebWorker) Listen ¶
func (ww *WasmSharedWebWorker) Listen(ctx context.Context) (<-chan types.MessageEventMessage, error)
Listen sends message events on a channel for events fired by port.postMessage() calls inside the Worker's. Stops the listener and closes the channel when ctx is canceled.
func (*WasmSharedWebWorker) PostMessage ¶
PostMessage sends data in a message to the worker, optionally transferring ownership of all items in transfers.
func (*WasmSharedWebWorker) Start ¶
func (ww *WasmSharedWebWorker) Start() error
type WasmSharedWebWorkerConn ¶
type WasmSharedWebWorkerConn struct { // If this is not specified, `Start` will create a UUIDv4 for it and populate back. Name string // This can be a relative path on the server, or an abosolute URL. Path string // If the Args field is empty or nil, Run uses {Path}. Args []string // Each entry is of the form "key=value". // If Env is nil, the new Web Worker uses the current context's // environment. // If Env contains duplicate environment keys, only the last // value in the slice for each duplicate key is used. Env []string // This is populated in the Start(). URL string // contains filtered or unexported fields }
WasmSharedWebWorkerConn is a high level wrapper around the WasmSharedWebWorker, which provides a full duplex connection between the web worker. On the web worker, it is expected to call the SelfSharedConn.SetupConn() to build up the connection.
func (*WasmSharedWebWorkerConn) Close ¶
func (conn *WasmSharedWebWorkerConn) Close() error
Close closes this WasmSharedWebWorkerConn at the outside and notify the web worker.
func (*WasmSharedWebWorkerConn) Connect ¶
func (conn *WasmSharedWebWorkerConn) Connect() (err error)
Connect creates a new WasmSharedWebWorkerConn to an active Shared Web Worker. Only the conn.Name and conn.URL matters.
func (*WasmSharedWebWorkerConn) EventChannel ¶
func (conn *WasmSharedWebWorkerConn) EventChannel() <-chan types.MessageEventMessage
EventChannel returns the channel that receives events sent from the Web Worker.
func (*WasmSharedWebWorkerConn) PostMessage ¶
PostMessage sends data in a message to the worker, optionally transferring ownership of all items in transfers.
func (*WasmSharedWebWorkerConn) Start ¶
func (conn *WasmSharedWebWorkerConn) Start() (*WasmSharedWebWorkerMgmtConn, error)
Start starts a new Shared Web Worker. It spins up a goroutine to receive the events from the Web Worker, and exposes a channel for consuming those events, which can be accessed by the `EventChannel()` method. It will fail if the Shared Web Worker already exists. In this case, use Connect() instead. The returned WasmSharedWebWorkerMgmtConn is a special connection, that is used to manage the web worker, or create another WasmSharedWebWorkerConn to this web worker via its Connect() method.
func (*WasmSharedWebWorkerConn) Wait ¶
func (conn *WasmSharedWebWorkerConn) Wait()
Wait waits for the controller's internal event loop to quit. This can be caused by the worker closes itself.
type WasmSharedWebWorkerMgmtConn ¶
type WasmSharedWebWorkerMgmtConn struct {
// contains filtered or unexported fields
}
WasmSharedWebWorkerMgmtConn is a connection to a newly started Shared Web Worker. It is only meant to: - Receive stdout/stderr from the worker, in form of the message event. - Send mgmt message events to the worker, including:
- Close event to let it close itself
- SetWriteToConsole event to let it write to console
- SetWriteToController event to let it write to this port back to the controller
func (*WasmSharedWebWorkerMgmtConn) Close ¶
func (c *WasmSharedWebWorkerMgmtConn) Close() error
Close mimics the terminate method of the DedicatedWorkerGlobalScope, but more gracefully. It sends a close message to the shared worker, which will in turn relay the close message back to the outside, and close itself in the meanwhile.
func (*WasmSharedWebWorkerMgmtConn) Connect ¶
func (c *WasmSharedWebWorkerMgmtConn) Connect() (conn *WasmSharedWebWorkerConn, err error)
Connect is a utility function taht creates a new WasmSharedWebWorkerConn and connect it to the active Shared Web Worker.
func (*WasmSharedWebWorkerMgmtConn) SetWriteToConsole ¶
func (c *WasmSharedWebWorkerMgmtConn) SetWriteToConsole() error
SetWriteToConsole instructs the worker to write its stdout/stderr to console
func (*WasmSharedWebWorkerMgmtConn) SetWriteToController ¶
func (c *WasmSharedWebWorkerMgmtConn) SetWriteToController() error
SetWriteToController instructs the worker to write its stdout/stderr to controller, which can be retrieved by Stdout(), Stderr().
func (*WasmSharedWebWorkerMgmtConn) Stderr ¶
func (c *WasmSharedWebWorkerMgmtConn) Stderr() io.ReadCloser
Stderr returns an io.ReadCloser that streams out the stderr of the web worker as long as its target write destination implementation is not modified to redirect to other sinks
func (*WasmSharedWebWorkerMgmtConn) Stdout ¶
func (c *WasmSharedWebWorkerMgmtConn) Stdout() io.ReadCloser
Stdout returns an io.ReadCloser that streams out the stdout of the web worker as long as its target write destination is not modified to redirect to other sinks
func (*WasmSharedWebWorkerMgmtConn) Wait ¶
func (c *WasmSharedWebWorkerMgmtConn) Wait()
Wait waits for the controller's internal event loop to quit. This can be caused by the worker closes itself.
type WasmWebWorker ¶
type WasmWebWorker struct { // Name specifies an identifying name for the DedicatedWorkerGlobalScope representing the scope of the worker, which is mainly useful for debugging purposes. // If this is not specified, `Start` will create a UUIDv4 for it and populate back. Name string // Path is the path of the WASM to run as the Web Worker. // This can be a relative path on the server, or an abosolute URL. Path string // Args holds command line arguments, including the WASM as Args[0]. // If the Args field is empty or nil, Run uses {Path}. Args []string // Env specifies the environment of the process. // Each entry is of the form "key=value". // If Env is nil, the new Web Worker uses the current context's // environment. // If Env contains duplicate environment keys, only the last // value in the slice for each duplicate key is used. Env []string // contains filtered or unexported fields }
func (*WasmWebWorker) Listen ¶
func (ww *WasmWebWorker) Listen(ctx context.Context) (<-chan types.MessageEventMessage, error)
Listen sends message events on a channel for events fired by self.postMessage() calls inside the Worker's global scope. Stops the listener and closes the channel when ctx is canceled.
func (*WasmWebWorker) PostMessage ¶
PostMessage sends data in a message to the worker, optionally transferring ownership of all items in transfers.
func (*WasmWebWorker) Start ¶
func (ww *WasmWebWorker) Start() error
func (*WasmWebWorker) Terminate ¶
func (ww *WasmWebWorker) Terminate()
Terminate immediately terminates the Worker.
type WasmWebWorkerConn ¶
type WasmWebWorkerConn struct { // Name specifies an identifying name for the DedicatedWorkerGlobalScope representing the scope of the worker, which is mainly useful for debugging purposes. // If this is not specified, `Start` will create a UUIDv4 for it and populate back. Name string // Path is the path of the WASM to run as the Web Worker. // This can be a relative path on the server, or an abosolute URL. Path string // Args holds command line arguments, including the WASM as Args[0]. // If the Args field is empty or nil, Run uses {Path}. Args []string // Env specifies the environment of the process. // Each entry is of the form "key=value". // If Env is nil, the new Web Worker uses the current context's // environment. // If Env contains duplicate environment keys, only the last // value in the slice for each duplicate key is used. Env []string Stdout io.Writer Stderr io.Writer // contains filtered or unexported fields }
WasmWebWorkerConn is a high level wrapper around the WasmWebWorker, which provides a full duplex connection between the web worker. On the web worker, it is expected to call the SelfConn.SetupConn() to build up the connection.
func (*WasmWebWorkerConn) EventChannel ¶
func (conn *WasmWebWorkerConn) EventChannel() <-chan types.MessageEventMessage
EventChannel returns the channel that receives events sent from the Web Worker.
func (*WasmWebWorkerConn) PostMessage ¶
PostMessage sends data in a message to the worker, optionally transferring ownership of all items in transfers.
func (*WasmWebWorkerConn) Start ¶
func (conn *WasmWebWorkerConn) Start() (err error)
Start starts a new Web Worker. It spins up a goroutine to receive the events from the Web Worker, and exposes a channel for consuming those events, which can be accessed by the `EventChannel()` method.
func (*WasmWebWorkerConn) StderrPipe ¶
func (conn *WasmWebWorkerConn) StderrPipe() (io.ReadCloser, error)
StderrPipe returns a channel that will be connected to the worker's standard error when the worker starts.
Once the worker is exited (no matter closed by itself or terminated), the channel will be closed by the WasmWebWorkerConn. So no need to close the channel themselves.
func (*WasmWebWorkerConn) StdoutPipe ¶
func (conn *WasmWebWorkerConn) StdoutPipe() (io.ReadCloser, error)
StdoutPipe returns a channel that will be connected to the worker's standard output when the worker starts.
Once the worker is exited (no matter closed by itself or terminated), the channel will be closed by the WasmWebWorkerConn. So no need to close the channel themselves.
func (*WasmWebWorkerConn) Terminate ¶
func (conn *WasmWebWorkerConn) Terminate()
Terminate immediately terminates the Worker. Meanwhile, it stops the internal event loop, which makes the `Wait` to return.
func (*WasmWebWorkerConn) Wait ¶
func (conn *WasmWebWorkerConn) Wait()
Wait waits for the controller's internal event loop to quit. This can be caused by either worker closes itself, or controler calls `Terminate`.
type WebWorkerCloseFunc ¶
type WebWorkerCloseFunc func() error