git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 1171580743394a34306e2a12800ea5606f7e5d67

Files: 1171580743394a34306e2a12800ea5606f7e5d67 / index.js

1068 bytesRaw
1const Kernel = require('./index.js')
2
3module.exports = class Hypervisor {
4 constructor (opts) {
5 this._opts = {
6 state: {},
7 imports: [],
8 hypervisor: this
9 }
10
11 Object.assign(this._opts, opts)
12 this._runningVMs = new Map()
13 }
14
15 set (path, value) {
16 return this._opts.graph.set(this._opts.state, path, value)
17 }
18
19 sendMessage (portObj, message) {
20 const vm = this.getInstaceFromPort(portObj)
21 vm.queue(message)
22 }
23
24 async getVMFromPort (port) {
25 const id = Kernel.id(port)
26 let kernel = this._vms.get(id)
27 if (!kernel) {
28 // load the container from the state
29 await this.graph.tree(port, 2)
30 kernel = new Kernel()
31 kernel.on('idle', () => {
32 this._vms.delete(id)
33 })
34 this._vms.set(id, kernel)
35 }
36 }
37
38 // given a port, wait untill its source contract has reached the threshold
39 // tick count
40 async waitOnPort (port, ticks) {
41 let kernel = await this.getVMFromPort(port)
42 return kernel.wait(ticks)
43 }
44
45 addVM (container) {
46 this._vms.type = container.type
47 }
48}
49

Built with git-ssb-web