git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: b4f2286715e5d94ee25ada50027f1690079cca1b

Files: b4f2286715e5d94ee25ada50027f1690079cca1b / message.js

836 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.hops = 0
17 this._vistedAgents = []
18 }
19
20 finished () {
21 if (this.sync) {
22 this._vistedAgents.pop()
23 }
24 }
25
26 addVistedKernel (kernel) {
27 const parentMessage = kernel._messageQueue.currentMessage
28 this.hops++
29 if (this.sync && parentMessage) {
30 this._vistedAgents = parentMessage._vistedAgents
31 this._vistedAgents.push(kernel)
32 }
33 }
34
35 isCyclic (kernel) {
36 return this.sync && this._vistedAgents.some(process => process === kernel)
37 }
38}
39

Built with git-ssb-web