Created
July 21, 2017 18:59
-
-
Save axic/eb4d659047a55c60a42a74b39182b660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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