git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 08886ada2409d7516bf4a5654c170fa62fe5e439

Files: 08886ada2409d7516bf4a5654c170fa62fe5e439 / message.js

781 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 sending (kernel, parentMessage) {
27 this.hops++
28 if (this.sync && parentMessage) {
29 this._vistedAgents = parentMessage._vistedAgents
30 this._vistedAgents.push(kernel)
31 }
32 }
33
34 isCyclic (kernel) {
35 return this.sync && this._vistedAgents.some(process => process === kernel)
36 }
37}
38

Built with git-ssb-web