git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 8716d3e0c84403a10b8fd9d5199ae126cb8f8577

Files: 8716d3e0c84403a10b8fd9d5199ae126cb8f8577 / message.js

1022 bytesRaw
1const U128 = require('fixed-bn.js').U128
2
3module.exports = class Message {
4 constructor (opts = {}) {
5 const defaults = {
6 // call infromation
7 to: [],
8 from: [],
9 data: new Uint8Array(),
10 atomic: true,
11 // resource info
12 gas: new U128(0),
13 gasPrices: new U128(0)
14 }
15 Object.assign(this, defaults, opts)
16 this.hops = 0
17 this._visitedKernels = []
18 this._resultPromise = new Promise((resolve, reject) => {
19 this._resolve = resolve
20 })
21 }
22
23 result () {
24 return this._resultPromise
25 }
26
27 nextPort () {
28 return this.to[this.hops]
29 }
30
31 _respond (result) {
32 this._resolve(result)
33 }
34
35 _finish () {
36 this._visitedKernels.pop()
37 }
38
39 _visited (kernel, currentMessage) {
40 if (currentMessage && this !== currentMessage) {
41 this._visitedKernels = currentMessage._visitedKernels
42 }
43 this._visitedKernels.push(kernel)
44 }
45
46 _isCyclic (kernel) {
47 return this.atomic && this._visitedKernels.some(process => process === kernel)
48 }
49}
50

Built with git-ssb-web