git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 2d5edf066ff154d5fc07115a7b1b66bcc2899f57

Files: 2d5edf066ff154d5fc07115a7b1b66bcc2899f57 / message.js

862 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 nextPort () {
21 this.toPort = this.to[this.hops]
22 this.hops++
23 return this.toPort
24 }
25
26 finished () {
27 if (this.sync) {
28 this._vistedAgents.pop()
29 }
30 }
31
32 sending (kernel, parentMessage) {
33 if (this.sync && parentMessage) {
34 this._vistedAgents = parentMessage._vistedAgents
35 this._vistedAgents.push(kernel)
36 }
37 }
38
39 isCyclic (kernel) {
40 return this.sync && this._vistedAgents.some(process => process === kernel)
41 }
42}
43

Built with git-ssb-web