git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 9bb00a66c6590ce780568e10d649be74c66ce1e6

Files: 9bb00a66c6590ce780568e10d649be74c66ce1e6 / message.js

981 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 atomic: 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._vistedKernels = []
18 this._resultPromise = new Promise((resolve, reject) => {
19 this._resolve = resolve
20 })
21 }
22
23 _finish (result) {
24 if (this.atomic) {
25 this._vistedKernels.pop()
26 if (!this._vistedKernels.length) {
27 this._resolve(result)
28 }
29 }
30 }
31
32 result () {
33 return this._resultPromise
34 }
35
36 nextPort () {
37 return this.to[this.hops++]
38 }
39
40 addVistedKernel (kernel) {
41 if (this.atomic) {
42 this._vistedKernels.push(kernel)
43 }
44 }
45
46 isCyclic (kernel) {
47 return this.sync && this._vistedKernels.some(process => process === kernel)
48 }
49}
50

Built with git-ssb-web