Skip to content

Instantly share code, notes, and snippets.

@axic
Created July 21, 2017 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axic/eb4d659047a55c60a42a74b39182b660 to your computer and use it in GitHub Desktop.
Save axic/eb4d659047a55c60a42a74b39182b660 to your computer and use it in GitHub Desktop.
// the Hypervisor starts an manages "containers"
class PrimeaContainer {
// the constructor is given an instance of the kernel
// https://github.com/primea/js-primea-hypervisor/blob/master/docs/kernel.md
constructor (kernel) {
this.kernel = kernel
}
// this method runs once when the container is initially created. It is given
// a message with a single port, which is a channel to its parent with the
// exception of the root container (the container that is intailial created)
initialize (message) {
const port = message.ports[0]
// the root container doesn't get a port
if (port) {
this.kernel.ports.bind('parent', port)
}
}
// the function is called for each message that a container gets
run (message) {
if (message.data === 'bindPort') {
this.kernel.ports.bind('channel', message.ports[0])
} else
throw new Error('Unimplemented message: ' + message.data)
}
onIdle () {
this.kernel.shutdown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment