Files: 841228acfa1dad00f990ebe18290a46130f85d5d / message.js
1020 bytesRaw
1 | const U256 = require('./deps/u256.js') |
2 | |
3 | module.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._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