git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 1e3ac999b894c127c15636b20fa61d8a5e60dd0f

Merge pull request #128 from primea/abstract-container

Use abstract container
wanderer authored on 7/24/2017, 1:39:31 AM
GitHub committed on 7/24/2017, 1:39:31 AM
Parent: c369709837d3b46f11f96b69f996371d77256e62
Parent: 32fb42f45694ffa0d857bbffa0fa4ba3adede028

Files changed

examples/index.jschanged
package.jsonchanged
examples/index.jsView
@@ -1,42 +1,37 @@
11 const IPFS = require('ipfs')
22 const Hypervisor = require('../')
3+const AbstractContainer = require('primea-abstract-container')
34
45 // the hypervisor store all of it's state using ipfs.dag api
56 // https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag
67 const node = new IPFS({
78 start: false
89 })
910
1011 // the Hypervisor starts an manages "containers"
11-class ExampleContainer {
12- // the constructor is given an instance of the kernel
13- // https://github.com/primea/js-primea-hypervisor/blob/master/docs/kernel.md
14- constructor (kernel) {
15- this.kernel = kernel
16- }
17-
12+class ExampleContainer extends AbstractContainer {
1813 // this method runs once when the container is intailly created. It is given
1914 // a message with a single port, which is a channel to its parent with the
2015 // exception of the root container (the container that is intailial created)
21- initialize (message) {
16+ async initialize (message) {
2217 const port = message.ports[0]
2318 // the root container doesn't get a port
2419 if (port) {
2520 this.kernel.ports.bind('parent', port)
21+ } else {
22+ super.intialize(message)
2623 }
2724 }
2825
2926 // the function is called for each message that a container gets
30- run (message) {
27+ async run (message) {
3128 if (message.data === 'bindPort') {
3229 this.kernel.ports.bind('channel', message.ports[0])
30+ } else {
31+ super.run(message)
3332 }
3433 }
35-
36- onIdle () {
37- this.kernel.shutdown()
38- }
3934 }
4035
4136 // wait untill the ipfs node is ready
4237 node.on('ready', async() => {
package.jsonView
@@ -32,8 +32,9 @@
3232 "dependencies": {
3333 "binary-search-insert": "^1.0.3",
3434 "bn.js": "^4.11.6",
3535 "ipld-graph-builder": "1.2.2",
36+ "primea-abstract-container": "0.0.1",
3637 "primea-message": "0.0.1"
3738 },
3839 "devDependencies": {
3940 "coveralls": "^2.13.1",

Built with git-ssb-web