Commit 1e3ac999b894c127c15636b20fa61d8a5e60dd0f
Merge pull request #128 from primea/abstract-container
Use abstract containerwanderer 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.js | changed |
package.json | changed |
examples/index.js | ||
---|---|---|
@@ -1,42 +1,37 @@ | ||
1 | 1 | const IPFS = require('ipfs') |
2 | 2 | const Hypervisor = require('../') |
3 | +const AbstractContainer = require('primea-abstract-container') | |
3 | 4 | |
4 | 5 | // the hypervisor store all of it's state using ipfs.dag api |
5 | 6 | // https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag |
6 | 7 | const node = new IPFS({ |
7 | 8 | start: false |
8 | 9 | }) |
9 | 10 | |
10 | 11 | // 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 { | |
18 | 13 | // this method runs once when the container is intailly created. It is given |
19 | 14 | // a message with a single port, which is a channel to its parent with the |
20 | 15 | // exception of the root container (the container that is intailial created) |
21 | - initialize (message) { | |
16 | + async initialize (message) { | |
22 | 17 | const port = message.ports[0] |
23 | 18 | // the root container doesn't get a port |
24 | 19 | if (port) { |
25 | 20 | this.kernel.ports.bind('parent', port) |
21 | + } else { | |
22 | + super.intialize(message) | |
26 | 23 | } |
27 | 24 | } |
28 | 25 | |
29 | 26 | // the function is called for each message that a container gets |
30 | - run (message) { | |
27 | + async run (message) { | |
31 | 28 | if (message.data === 'bindPort') { |
32 | 29 | this.kernel.ports.bind('channel', message.ports[0]) |
30 | + } else { | |
31 | + super.run(message) | |
33 | 32 | } |
34 | 33 | } |
35 | - | |
36 | - onIdle () { | |
37 | - this.kernel.shutdown() | |
38 | - } | |
39 | 34 | } |
40 | 35 | |
41 | 36 | // wait untill the ipfs node is ready |
42 | 37 | node.on('ready', async() => { |
Built with git-ssb-web