spawn

package
v0.11.2-0...-5e2af07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(f engine.Installer) error

Init checks if the current process has been created by Spawn.

If no, it returns nil and the original program can continue unmodified.

If no, it hijacks the process to run as a child worker controlled by its parent over a beam connection, with f exposed as a remote service. In this case Init never returns.

The hijacking process takes place as follows:

  • Open file descriptor 3 as a beam endpoint. If this fails, terminate the current process.
  • Start a new engine.
  • Call f.Install on the engine. Any handlers registered will be available for remote invocation by the parent.
  • Listen for beam messages from the parent and pass them to the handlers.
  • When the beam endpoint is closed by the parent, terminate the current process.

NOTE: Init must be called at the beginning of the same program calling Spawn. This is because Spawn approximates a "fork" by re-executing the current binary - where it expects spawn.Init to intercept the control flow and execute the worker code.

func Spawn

func Spawn() (*engine.Engine, error)

Spawn starts a new Engine in a child process and returns a proxy Engine through which it can be controlled.

The commands available on the child engine are determined by an earlier call to Init. It is important that Init be called at the very beginning of the current program - this allows it to be called as a re-execution hook in the child process.

Long story short, if you want to expose `myservice` in a child process, do this:

func main() {
    spawn.Init(myservice)
    [..]
    child, err := spawn.Spawn()
    [..]
    child.Job("dosomething").Run()
}

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL