Commit aff7fe3dbdadaa720feb5561633c1d5eb583f80d
update and rebuild docs
Norton Wang committed on 4/29/2018, 4:20:04 PMParent: 4ef01e25f0db10ce812670a695cf71a5ac9aba76
Files changed
actor.js | changed |
docs/actor.md | changed |
docs/hypervisor.md | changed |
index.js | changed |
actor.js | ||
---|---|---|
@@ -2,17 +2,18 @@ | ||
2 | 2 … | const nope = () => {} |
3 | 3 … | |
4 | 4 … | module.exports = class Actor { |
5 | 5 … | /** |
6 | - * the Actor manages the varous message passing functions and provides | |
6 … | + * the Actor manages the various message passing functions and provides | |
7 | 7 … | * an interface for the containers to use |
8 | 8 … | * @param {Object} opts |
9 | 9 … | * @param {ID} opts.id - the UUID of the Actor |
10 | - * @param {Object} opts.state - the state of the container | |
11 | - * @param {Object} opts.storage - the actor's persistant storage | |
10 … | + * @param {Object} opts.module - the module this actor was created from | |
11 … | + * @param {Object} opts.state - the state of the module | |
12 … | + * @param {Object} opts.storage - the actor's persistent storage | |
12 | 13 … | * @param {Object} opts.hypervisor - the instance of the hypervisor |
13 | 14 … | * @param {Number} opts.nonce |
14 | - * @param {Function} opts.container - the container constuctor and argments | |
15 … | + * @param {Function} opts.Container - the module constructor and arguments | |
15 | 16 … | */ |
16 | 17 … | constructor (opts) { |
17 | 18 … | Object.assign(this, opts) |
18 | 19 … | |
@@ -74,8 +75,9 @@ | ||
74 | 75 … | /** |
75 | 76 … | * creates an actor from a module and code |
76 | 77 … | * @param {Module} mod - the module |
77 | 78 … | * @param {Buffer} code - the code |
79 … | + * @return {ActorRef} | |
78 | 80 … | */ |
79 | 81 … | newActor (mod, code) { |
80 | 82 … | const modRef = this.createModule(mod, code) |
81 | 83 … | return this.createActor(modRef) |
@@ -84,8 +86,9 @@ | ||
84 | 86 … | /** |
85 | 87 … | * creates a modref from a module and code |
86 | 88 … | * @param {Module} mod - the module |
87 | 89 … | * @param {Buffer} code - the code |
90 … | + * @return {ModuleRef} | |
88 | 91 … | */ |
89 | 92 … | createModule (mod, code) { |
90 | 93 … | const id = this._generateNextId() |
91 | 94 … | return this.hypervisor.createModule(mod, code, id) |
@@ -93,8 +96,9 @@ | ||
93 | 96 … | |
94 | 97 … | /** |
95 | 98 … | * creates an actor from a modref |
96 | 99 … | * @param {ModuleRef} modRef - the modref |
100 … | + * @return {ActorRef} | |
97 | 101 … | */ |
98 | 102 … | createActor (modRef) { |
99 | 103 … | const id = this._generateNextId() |
100 | 104 … | return this.hypervisor.createActor(modRef, id) |
@@ -110,10 +114,9 @@ | ||
110 | 114 … | return id |
111 | 115 … | } |
112 | 116 … | |
113 | 117 … | /** |
114 | - * sends a message to a given port | |
115 | - * @param {Object} portRef - the port | |
118 … | + * sends a message | |
116 | 119 … | * @param {Message} message - the message |
117 | 120 … | */ |
118 | 121 … | send (message) { |
119 | 122 … | message._fromTicks = this.ticks |
docs/actor.md | ||
---|---|---|
@@ -6,86 +6,95 @@ | ||
6 | 6 … | - [shutdown][2] |
7 | 7 … | - [startup][3] |
8 | 8 … | - [runMessage][4] |
9 | 9 … | - [incrementTicks][5] |
10 | -- [createActor][6] | |
11 | -- [send][7] | |
10 … | +- [newActor][6] | |
11 … | +- [createModule][7] | |
12 … | +- [createActor][8] | |
13 … | +- [send][9] | |
12 | 14 … | |
13 | 15 … | ## constructor |
14 | 16 … | |
15 | -[actor.js:17-26][8] | |
16 | - | |
17 | -the Actor manages the varous message passing functions and provides | |
17 … | +the Actor manages the various message passing functions and provides | |
18 | 18 … | an interface for the containers to use |
19 | 19 … | |
20 | 20 … | **Parameters** |
21 | 21 … | |
22 | -- `opts` **[Object][9]** | |
22 … | +- `opts` **[Object][10]** | |
23 | 23 … | - `opts.id` **ID** the UUID of the Actor |
24 | - - `opts.state` **[Object][9]** the state of the container | |
25 | - - `opts.storage` **[Object][9]** the actor's persistant storage | |
26 | - - `opts.hypervisor` **[Object][9]** the instance of the hypervisor | |
27 | - - `opts.nonce` **[Number][10]** | |
28 | - - `opts.type` **[Number][10]** the container type | |
29 | - - `opts.container` **[Function][11]** the container constuctor and argments | |
24 … | + - `opts.module` **[Object][10]** the module this actor was created from | |
25 … | + - `opts.state` **[Object][10]** the state of the module | |
26 … | + - `opts.storage` **[Object][10]** the actor's persistent storage | |
27 … | + - `opts.hypervisor` **[Object][10]** the instance of the hypervisor | |
28 … | + - `opts.nonce` **[Number][11]** | |
29 … | + - `opts.Container` **[Function][12]** the module constructor and arguments | |
30 | 30 … | |
31 | 31 … | ## shutdown |
32 | 32 … | |
33 | -[actor.js:31-35][12] | |
34 | - | |
35 | 33 … | Runs the shutdown routine for the actor |
36 | 34 … | |
37 | 35 … | ## startup |
38 | 36 … | |
39 | -[actor.js:40-42][13] | |
40 | - | |
41 | 37 … | Runs the startup routine for the actor |
42 | 38 … | |
43 | 39 … | ## runMessage |
44 | 40 … | |
45 | -[actor.js:50-61][14] | |
46 | - | |
47 | 41 … | run the Actor with a given message |
48 | 42 … | |
49 | 43 … | **Parameters** |
50 | 44 … | |
51 | -- `message` **[object][9]** the message to run | |
52 | -- `method` **[String][15]** which method to run | |
45 … | +- `message` **[object][10]** the message to run | |
46 … | +- `method` **[String][13]** which method to run | |
53 | 47 … | |
54 | -Returns **[Promise][16]** | |
48 … | +Returns **[Promise][14]** | |
55 | 49 … | |
56 | 50 … | ## incrementTicks |
57 | 51 … | |
58 | -[actor.js:67-73][17] | |
59 | - | |
60 | 52 … | updates the number of ticks that the actor has run |
61 | 53 … | |
62 | 54 … | **Parameters** |
63 | 55 … | |
64 | -- `count` **[Number][10]** the number of ticks to add | |
56 … | +- `count` **[Number][11]** the number of ticks to add | |
65 | 57 … | |
66 | -## createActor | |
58 … | +## newActor | |
67 | 59 … | |
68 | -[actor.js:80-83][18] | |
60 … | +creates an actor from a module and code | |
69 | 61 … | |
70 | -creates an actor | |
62 … | +**Parameters** | |
71 | 63 … | |
64 … | +- `mod` **[Module][15]** the module | |
65 … | +- `code` **[Buffer][16]** the code | |
66 … | + | |
67 … | +Returns **ActorRef** | |
68 … | + | |
69 … | +## createModule | |
70 … | + | |
71 … | +creates a modref from a module and code | |
72 … | + | |
72 | 73 … | **Parameters** |
73 | 74 … | |
74 | -- `type` **Integer** the type id for the container | |
75 | -- `code` | |
76 | -- `message` **[Object][9]** an intial [message][19] to send newly created actor | |
75 … | +- `mod` **[Module][15]** the module | |
76 … | +- `code` **[Buffer][16]** the code | |
77 | 77 … | |
78 | -## send | |
78 … | +Returns **ModuleRef** | |
79 | 79 … | |
80 | -[actor.js:100-105][20] | |
80 … | +## createActor | |
81 | 81 … | |
82 | -sends a message to a given port | |
82 … | +creates an actor from a modref | |
83 | 83 … | |
84 | 84 … | **Parameters** |
85 | 85 … | |
86 … | +- `modRef` **ModuleRef** the modref | |
87 … | + | |
88 … | +Returns **ActorRef** | |
89 … | + | |
90 … | +## send | |
91 … | + | |
92 … | +sends a message | |
93 … | + | |
94 … | +**Parameters** | |
95 … | + | |
86 | 96 … | - `message` **Message** the message |
87 | -- `portRef` **[Object][9]** the port | |
88 | 97 … | |
89 | 98 … | [1]: #constructor |
90 | 99 … | |
91 | 100 … | [2]: #shutdown |
@@ -95,33 +104,25 @@ | ||
95 | 104 … | [4]: #runmessage |
96 | 105 … | |
97 | 106 … | [5]: #incrementticks |
98 | 107 … | |
99 | -[6]: #createactor | |
108 … | +[6]: #newactor | |
100 | 109 … | |
101 | -[7]: #send | |
110 … | +[7]: #createmodule | |
102 | 111 … | |
103 | -[8]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L17-L26 "Source code on GitHub" | |
112 … | +[8]: #createactor | |
104 | 113 … | |
105 | -[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | |
114 … | +[9]: #send | |
106 | 115 … | |
107 | -[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | |
116 … | +[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | |
108 | 117 … | |
109 | -[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function | |
118 … | +[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | |
110 | 119 … | |
111 | -[12]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L31-L35 "Source code on GitHub" | |
120 … | +[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function | |
112 | 121 … | |
113 | -[13]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L40-L42 "Source code on GitHub" | |
122 … | +[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | |
114 | 123 … | |
115 | -[14]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L50-L61 "Source code on GitHub" | |
124 … | +[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise | |
116 | 125 … | |
117 | -[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | |
126 … | +[15]: https://nodejs.org/api/modules.html | |
118 | 127 … | |
119 | -[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise | |
120 | - | |
121 | -[17]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L67-L73 "Source code on GitHub" | |
122 | - | |
123 | -[18]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L80-L83 "Source code on GitHub" | |
124 | - | |
125 | -[19]: https://github.com/primea/js-primea-message | |
126 | - | |
127 | -[20]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/actor.js#L100-L105 "Source code on GitHub" | |
128 … | +[16]: https://nodejs.org/api/buffer.html |
docs/hypervisor.md | ||
---|---|---|
@@ -4,157 +4,150 @@ | ||
4 | 4 … | |
5 | 5 … | - [constructor][1] |
6 | 6 … | - [send][2] |
7 | 7 … | - [loadActor][3] |
8 | -- [createActor][4] | |
9 | -- [createStateRoot][5] | |
10 | -- [setStateRoot][6] | |
11 | -- [registerContainer][7] | |
12 | -- [registerDriver][8] | |
8 … | +- [newActor][4] | |
9 … | +- [createModule][5] | |
10 … | +- [createActor][6] | |
11 … | +- [createStateRoot][7] | |
12 … | +- [setStateRoot][8] | |
13 … | +- [registerModule][9] | |
14 … | +- [registerDriver][10] | |
13 | 15 … | |
14 | 16 … | ## constructor |
15 | 17 … | |
16 | -[index.js:18-27][9] | |
18 … | +The Hypervisor manages module instances by instantiating them and | |
19 … | +destroying them when possible. It also facilitates locating Containers | |
17 | 20 … | |
18 | -The Hypervisor manages the container instances by instantiating them and | |
19 | -destorying them when possible. It also facilitates localating Containers | |
20 | - | |
21 | 21 … | **Parameters** |
22 | 22 … | |
23 | -- `opts` **[Object][10]** | |
24 | - - `opts.tree` **[Object][10]** a [radix tree][11] to store the state | |
25 | - - `opts.container` **[Array][12]** an array of containers to regester | |
26 | - - `opts.drivers` **[Array][12]** an array of drivers to install | |
27 | - - `opts.meter` **[boolean][13]** whether to meter gas or not (optional, default `true`) | |
23 … | +- `opts` **[Object][11]** | |
24 … | + - `opts.tree` **[Object][11]** a [radix tree][12] to store the state | |
25 … | + - `opts.modules` **[Array][13]** an array of modules to register | |
26 … | + - `opts.drivers` **[Array][13]** an array of drivers to install | |
27 … | + - `opts.meter` **[boolean][14]** whether to meter gas or not (optional, default `true`) | |
28 | 28 … | |
29 | 29 … | ## send |
30 | 30 … | |
31 | -[index.js:34-39][14] | |
32 | - | |
33 | 31 … | sends a message(s). If an array of message is given the all the messages will be sent at once |
34 | 32 … | |
35 | 33 … | **Parameters** |
36 | 34 … | |
37 | 35 … | - `messages` |
38 | -- `message` **[Object][10]** the [message][15] to send | |
36 … | +- `message` **[Object][11]** the [message][15] to send | |
39 | 37 … | |
40 | -Returns **[Promise][16]** a promise that resolves once the receiving container is loaded | |
38 … | +Returns **[Promise][16]** a promise that resolves once the receiving module is loaded | |
41 | 39 … | |
42 | 40 … | ## loadActor |
43 | 41 … | |
44 | -[index.js:46-70][17] | |
45 | - | |
46 | 42 … | loads an actor from the tree given its id |
47 | 43 … | |
48 | 44 … | **Parameters** |
49 | 45 … | |
50 | 46 … | - `id` **ID** |
51 | 47 … | |
52 | 48 … | Returns **[Promise][16]<Actor>** |
53 | 49 … | |
54 | -## createActor | |
50 … | +## newActor | |
55 | 51 … | |
56 | -[index.js:78-102][18] | |
52 … | +creates an actor from a module and code | |
57 | 53 … | |
58 | -creates an instance of an Actor | |
54 … | +**Parameters** | |
59 | 55 … | |
56 … | +- `mod` **[Module][17]** the module | |
57 … | +- `code` **[Buffer][18]** the code | |
58 … | + | |
59 … | +Returns **ActorRef** | |
60 … | + | |
61 … | +## createModule | |
62 … | + | |
63 … | +creates a modref from a module and code | |
64 … | + | |
60 | 65 … | **Parameters** |
61 | 66 … | |
62 | -- `type` **Integer** the type id for the container | |
63 | -- `code` | |
64 | -- `id` **[Object][10]** the id for the actor (optional, default `{nonce:this.nonce++,parent:null}`) | |
65 | -- `message` **[Object][10]** an intial [message][15] to send newly created actor | |
67 … | +- `mod` **[Module][17]** the module | |
68 … | +- `code` **[Buffer][18]** the code | |
69 … | +- `id` **id** the id for the module (optional, default `{nonce:this.nonce++,parent:null}`) | |
66 | 70 … | |
67 | -## createStateRoot | |
71 … | +Returns **ModuleRef** | |
68 | 72 … | |
69 | -[index.js:116-124][19] | |
73 … | +## createActor | |
70 | 74 … | |
71 | -creates a state root starting from a given container and a given number of | |
72 | -ticks | |
75 … | +creates an instance of an Actor | |
73 | 76 … | |
74 | 77 … | **Parameters** |
75 | 78 … | |
76 | -- `ticks` **[Number][20]** the number of ticks at which to create the state root | |
79 … | +- `modRef` | |
80 … | +- `id` **[Object][11]** the id for the actor (optional, default `{nonce:this.nonce++,parent:null}`) | |
81 … | +- `type` **ModuleRef** the modref | |
77 | 82 … | |
83 … | +Returns **ActorRef** | |
84 … | + | |
85 … | +## createStateRoot | |
86 … | + | |
87 … | +creates a state root when scheduler is idle | |
88 … | + | |
78 | 89 … | Returns **[Promise][16]** |
79 | 90 … | |
80 | 91 … | ## setStateRoot |
81 | 92 … | |
82 | -[index.js:131-135][21] | |
83 | - | |
84 | 93 … | set the state root. The promise must resolve before creating or sending any more messages to the hypervisor |
85 | 94 … | |
86 | 95 … | **Parameters** |
87 | 96 … | |
88 | -- `stateRoot` **[Buffer][22]** | |
97 … | +- `stateRoot` **[Buffer][18]** | |
89 | 98 … | |
90 | 99 … | Returns **[Promise][16]** |
91 | 100 … | |
92 | -## registerContainer | |
101 … | +## registerModule | |
93 | 102 … | |
94 | -[index.js:141-143][23] | |
103 … | +registers a module with the hypervisor | |
95 | 104 … | |
96 | -regesters a container with the hypervisor | |
97 | - | |
98 | 105 … | **Parameters** |
99 | 106 … | |
100 | -- `Constructor` **[Function][24]** the container's constuctor | |
107 … | +- `Constructor` **[Function][19]** the module's constructor | |
101 | 108 … | |
102 | 109 … | ## registerDriver |
103 | 110 … | |
104 | -[index.js:149-151][25] | |
105 | - | |
106 | 111 … | register a driver with the hypervisor |
107 | 112 … | |
108 | 113 … | **Parameters** |
109 | 114 … | |
110 | -- `driver` **driver** | |
115 … | +- `driver` **Driver** | |
111 | 116 … | |
112 | 117 … | [1]: #constructor |
113 | 118 … | |
114 | 119 … | [2]: #send |
115 | 120 … | |
116 | 121 … | [3]: #loadactor |
117 | 122 … | |
118 | -[4]: #createactor | |
123 … | +[4]: #newactor | |
119 | 124 … | |
120 | -[5]: #createstateroot | |
125 … | +[5]: #createmodule | |
121 | 126 … | |
122 | -[6]: #setstateroot | |
127 … | +[6]: #createactor | |
123 | 128 … | |
124 | -[7]: #registercontainer | |
129 … | +[7]: #createstateroot | |
125 | 130 … | |
126 | -[8]: #registerdriver | |
131 … | +[8]: #setstateroot | |
127 | 132 … | |
128 | -[9]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L18-L27 "Source code on GitHub" | |
133 … | +[9]: #registermodule | |
129 | 134 … | |
130 | -[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | |
135 … | +[10]: #registerdriver | |
131 | 136 … | |
132 | -[11]: https://github.com/dfinity/js-dfinity-radix-tree | |
137 … | +[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | |
133 | 138 … | |
134 | -[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | |
139 … | +[12]: https://github.com/dfinity/js-dfinity-radix-tree | |
135 | 140 … | |
136 | -[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean | |
141 … | +[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | |
137 | 142 … | |
138 | -[14]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L34-L39 "Source code on GitHub" | |
143 … | +[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean | |
139 | 144 … | |
140 | 145 … | [15]: https://github.com/primea/js-primea-message |
141 | 146 … | |
142 | 147 … | [16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise |
143 | 148 … | |
144 | -[17]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L46-L70 "Source code on GitHub" | |
149 … | +[17]: https://nodejs.org/api/modules.html | |
145 | 150 … | |
146 | -[18]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L78-L102 "Source code on GitHub" | |
151 … | +[18]: https://nodejs.org/api/buffer.html | |
147 | 152 … | |
148 | -[19]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L116-L124 "Source code on GitHub" | |
149 | - | |
150 | -[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | |
151 | - | |
152 | -[21]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L131-L135 "Source code on GitHub" | |
153 | - | |
154 | -[22]: https://nodejs.org/api/buffer.html | |
155 | - | |
156 | -[23]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L141-L143 "Source code on GitHub" | |
157 | - | |
158 | -[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function | |
159 | - | |
160 | -[25]: https://github.com/dfinity/js-primea/blob/1f8affb407f9413e9af400e3cc7408ece8274347/index.js#L149-L151 "Source code on GitHub" | |
153 … | +[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function |
index.js | ||
---|---|---|
@@ -4,13 +4,13 @@ | ||
4 | 4 … | const {decoder, generateId, ModuleRef, ActorRef} = require('primea-objects') |
5 | 5 … | |
6 | 6 … | module.exports = class Hypervisor { |
7 | 7 … | /** |
8 | - * The Hypervisor manages the container instances by instantiating them and | |
9 | - * destorying them when possible. It also facilitates localating Containers | |
8 … | + * The Hypervisor manages module instances by instantiating them and | |
9 … | + * destroying them when possible. It also facilitates locating Containers | |
10 | 10 … | * @param {Object} opts |
11 | 11 … | * @param {Object} opts.tree - a [radix tree](https://github.com/dfinity/js-dfinity-radix-tree) to store the state |
12 | - * @param {Array} opts.container - an array of containers to regester | |
12 … | + * @param {Array} opts.modules - an array of modules to register | |
13 | 13 … | * @param {Array} opts.drivers - an array of drivers to install |
14 | 14 … | * @param {boolean} [opts.meter=true] - whether to meter gas or not |
15 | 15 … | */ |
16 | 16 … | constructor (opts) { |
@@ -26,9 +26,9 @@ | ||
26 | 26 … | |
27 | 27 … | /** |
28 | 28 … | * sends a message(s). If an array of message is given the all the messages will be sent at once |
29 | 29 … | * @param {Object} message - the [message](https://github.com/primea/js-primea-message) to send |
30 | - * @returns {Promise} a promise that resolves once the receiving container is loaded | |
30 … | + * @returns {Promise} a promise that resolves once the receiving module is loaded | |
31 | 31 … | */ |
32 | 32 … | send (messages) { |
33 | 33 … | if (!Array.isArray(messages)) { |
34 | 34 … | messages = [messages] |
@@ -46,8 +46,9 @@ | ||
46 | 46 … | const [module, storage] = await Promise.all([ |
47 | 47 … | this.tree.graph.tree(state.node, '1'), |
48 | 48 … | this.tree.graph.get(state.node, '2') |
49 | 49 … | ]) |
50 … | + await this.tree.graph.get(module[1][1], '') | |
50 | 51 … | const [type, nonce] = state.value |
51 | 52 … | const Container = this._modules[type] |
52 | 53 … | |
53 | 54 … | // create a new actor instance |
@@ -65,24 +66,38 @@ | ||
65 | 66 … | await actor.startup() |
66 | 67 … | return actor |
67 | 68 … | } |
68 | 69 … | |
70 … | + /** | |
71 … | + * creates an actor from a module and code | |
72 … | + * @param {Module} mod - the module | |
73 … | + * @param {Buffer} code - the code | |
74 … | + * @return {ActorRef} | |
75 … | + */ | |
69 | 76 … | newActor (mod, code) { |
70 | 77 … | const modRef = this.createModule(mod, code) |
71 | 78 … | return this.createActor(modRef) |
72 | 79 … | } |
73 | 80 … | |
81 … | + /** | |
82 … | + * creates a modref from a module and code | |
83 … | + * @param {Module} mod - the module | |
84 … | + * @param {Buffer} code - the code | |
85 … | + * @param {id} id - the id for the module | |
86 … | + * @return {ModuleRef} | |
87 … | + */ | |
74 | 88 … | createModule (mod, code, id = {nonce: this.nonce++, parent: null}) { |
75 | 89 … | const moduleID = generateId(id) |
76 | 90 … | const Module = this._modules[mod.typeId] |
77 | - const {exports, state} = Module.onCreation(mod.code) | |
91 … | + const {exports, state} = Module.onCreation(code) | |
78 | 92 … | return new ModuleRef(moduleID, mod.typeId, exports, state, code) |
79 | 93 … | } |
80 | 94 … | |
81 | 95 … | /** |
82 | 96 … | * creates an instance of an Actor |
83 | - * @param {Integer} type - the type id for the container | |
97 … | + * @param {ModuleRef} type - the modref | |
84 | 98 … | * @param {Object} id - the id for the actor |
99 … | + * @return {ActorRef} | |
85 | 100 … | */ |
86 | 101 … | createActor (modRef, id = {nonce: this.nonce++, parent: null}) { |
87 | 102 … | const actorId = generateId(id) |
88 | 103 … | const metaData = [modRef.type, 0] |
@@ -102,20 +117,18 @@ | ||
102 | 117 … | return new ActorRef(actorId, modRef) |
103 | 118 … | } |
104 | 119 … | |
105 | 120 … | /** |
106 | - * creates a state root starting from a given container and a given number of | |
107 | - * ticks | |
108 | - * @param {Number} ticks the number of ticks at which to create the state root | |
121 … | + * creates a state root when scheduler is idle | |
109 | 122 … | * @returns {Promise} |
110 | 123 … | */ |
111 | 124 … | async createStateRoot () { |
112 | 125 … | if (this.scheduler._running) { |
113 | 126 … | await new Promise((resolve, reject) => { |
114 | 127 … | this.scheduler.once('idle', resolve) |
115 | 128 … | }) |
116 | 129 … | } |
117 | - // console.log(JSON.stringify(this.tree.root, null, 2)) | |
130 … | + | |
118 | 131 … | await this.tree.set(Buffer.from([0]), this.nonce) |
119 | 132 … | return this.tree.flush() |
120 | 133 … | } |
121 | 134 … | |
@@ -130,18 +143,18 @@ | ||
130 | 143 … | this.nonce = node.value |
131 | 144 … | } |
132 | 145 … | |
133 | 146 … | /** |
134 | - * regesters a container with the hypervisor | |
135 | - * @param {Function} Constructor - the container's constuctor | |
147 … | + * registers a module with the hypervisor | |
148 … | + * @param {Function} Constructor - the module's constructor | |
136 | 149 … | */ |
137 | 150 … | registerModule (Constructor) { |
138 | 151 … | this._modules[Constructor.typeId] = Constructor |
139 | 152 … | } |
140 | 153 … | |
141 | 154 … | /** |
142 | 155 … | * register a driver with the hypervisor |
143 | - * @param {driver} driver | |
156 … | + * @param {Driver} driver | |
144 | 157 … | */ |
145 | 158 … | registerDriver (driver) { |
146 | 159 … | driver.startup(this) |
147 | 160 … | this.scheduler.drivers.set(driver.id.toString(), driver) |
Built with git-ssb-web