git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: fe2d3d73d28c55f28860b137e3990bae31fbd26b

Files: fe2d3d73d28c55f28860b137e3990bae31fbd26b / message.js

924 bytesRaw
1const U256 = require('./deps/u256.js')
2
3module.exports = class Message {
4 constructor (opts = {}) {
5 const defaults = {
6 // call infromation
7 to: [],
8 from: [],
9 data: new Uint8Array(),
10 sync: true,
11 // resource info
12 gas: new U256(0),
13 gasPrices: new U256(0)
14 }
15 Object.assign(this, defaults, opts)
16 this._index = 0
17 this._parentProcesses = []
18 }
19
20 nextPort () {
21 // this.from.push(message.toPort)
22 this.toPort = this.to[this._index]
23 this._index++
24 return this.toPort
25 }
26
27 finished () {
28 if (this.sync) {
29 this._parentProcesses.pop()
30 }
31 }
32
33 sending (kernel, parentMessage) {
34 if (this.sync && parentMessage) {
35 this._parentProcesses = parentMessage._parentProcesses
36 this._parentProcesses.push(kernel)
37 }
38 }
39
40 isCyclic (kernel) {
41 return this.sync && this._parentProcesses.some(process => process === kernel)
42 }
43}
44

Built with git-ssb-web