git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 1635a21816ba2086ab136257355c7a5550d7a7fd

Files: 1635a21816ba2086ab136257355c7a5550d7a7fd / index.js

982 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 getVMFromPort (port) {
25 const id = Kernel.id(port)
26 let kernel = this._vms.get(id)
27 if (!kernel) {
28 kernel = new Kernel(port)
29 kernel.on('idle', () => {
30 this._vms.delete(id)
31 })
32 this._vms.set(id, kernel)
33 }
34 }
35
36 // given a port, wait untill its source contract has reached the threshold
37 // tick count
38 async waitOnPort (port, ticks) {
39 let kernel = this.getVMFromPort(port)
40 const tickCount = await kernel.wait(ticks)
41 port.ticks = tickCount
42 return tickCount
43 }
44}
45

Built with git-ssb-web