Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler interface {
// GetVersion sets function to call when the version has been received
// from the webworker. If the version has already been gotten, the callback
// will be called right away.
GetVersion(callback func(string))
// SetVerbose sets if the compiler webworker should output
// status logs or not. This is useful when debugging.
SetVerbose(verbose bool)
// SetOutput redirects random problems in the compiler from being
// sent to the console and instead outputs them to the output box.
// These errors are typically from the compiler itself having problems,
// and not errors the compiler found in the code being sent to it, which
// will be returned as part of the "then" passed in when starting a compile.
SetOutput(out common.Output)
// SetCode updates the source code that the runner is working on.
//
// The given Go code is the set of entry-point virtual-files to use keyed
// with the name of the file, e.g. `main.go`.
// The value is the source code that corresponds to that file name.
// All this code is expected to be part of the main package.
// We currently don't allow auxiliary code for other packages.
//
// When the code is set, any packages that this code depends on will
// start preloading to reduce the time that compile takes.
// This will not check if the code has actually changed, it will assume
// that the code has been changed if this method is being called.
SetCode(goCode map[string]string)
// Compile asynchronously compiles the currently set Go code.
// When done the given callback is invoked with the resulting
// JavaScript code or an error if the compilation failed.
//
// If a previous compile is running, the other compile must finish
// prior to another one being started. If a compile is running
// this will return false to indicate the newest request was ignored.
// Otherwise, this will return true indicating a compile has started.
Compile(then func(string, error)) bool
}
Compiler is a wrapper for a webworker that is launched when the compiler is created. The webworker will perform compiles asynchronously. The code for the compiler webworker is found in playground/internal/cmd/compile.
This interface allow the compiler to be mocked during tests where running a webworker is not ideal or possible.
func NewCompiler ¶
func NewCompiler() Compiler
type Runner ¶
type Runner interface {
// SetOutput sets where the running code will output to.
// This may be called while code is running.
SetOutput(out common.Output)
// Run executes the given JavaScript code.
//
// If some code is already being run, this will stop it from running
// prior to starting some other code running.
Run(jsCode string)
// Stop will cancel a previous run, if anything is running, otherwise
// it will have no effect.
Stop()
}
Runner is a wrapper around a webworker launcher that launches javascript code in an isolated webworker so that it can run asynchronously and cancelled at any time.
This interface allow the runner to be mocked during tests where running a webworker is not ideal or possible.
Click to show internal directories.
Click to hide internal directories.