Commit c779344f6653a07ed5e2695bca74c9cbd0c66a19
updated docs
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 1/23/2018, 8:29:36 PM
Parent: 5a33099559b3af6b0c5c0e444a8d537471853b77
Files changed
actor.js | changed |
docs/inbox.md | deleted |
package-lock.json | changed |
package.json | changed |
scheduler.js | changed |
actor.js | ||
---|---|---|
@@ -14,9 +14,8 @@ | ||
14 | 14 | constructor (opts) { |
15 | 15 | Object.assign(this, opts) |
16 | 16 | |
17 | 17 | this.inbox = [] |
18 | - | |
19 | 18 | this.ticks = 0 |
20 | 19 | this.running = false |
21 | 20 | } |
22 | 21 |
docs/inbox.md | ||
---|---|---|
@@ -1,42 +1,0 @@ | ||
1 | -<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | |
2 | - | |
3 | -### Table of Contents | |
4 | - | |
5 | -- [constructor](#constructor) | |
6 | -- [queue](#queue) | |
7 | -- [nextMessage](#nextmessage) | |
8 | - | |
9 | -## constructor | |
10 | - | |
11 | -[inbox.js:24-31](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/inbox.js#L24-L31 "Source code on GitHub") | |
12 | - | |
13 | -The inbox manages and sorts incoming messages and provides functions | |
14 | -to wait on messages | |
15 | - | |
16 | -**Parameters** | |
17 | - | |
18 | -- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | |
19 | - - `opts.state` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | |
20 | - - `opts.hypervisor` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | |
21 | - | |
22 | -## queue | |
23 | - | |
24 | -[inbox.js:41-51](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/inbox.js#L41-L51 "Source code on GitHub") | |
25 | - | |
26 | -queues a message | |
27 | - | |
28 | -**Parameters** | |
29 | - | |
30 | -- `message` **Message** | |
31 | - | |
32 | -## nextMessage | |
33 | - | |
34 | -[inbox.js:58-91](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/inbox.js#L58-L91 "Source code on GitHub") | |
35 | - | |
36 | -Waits for the the next message if any | |
37 | - | |
38 | -**Parameters** | |
39 | - | |
40 | -- `timeout` **Integer** | |
41 | - | |
42 | -Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 341063 bytes New file size: 341262 bytes |
package.json | ||
---|---|---|
@@ -9,10 +9,8 @@ | ||
9 | 9 | "build:docs": "npm run build:docs:hypervisor && npm run build:docs:actor && npm run build:docs:scheduler && npm run build:docs:capsStore && npm run build:docs:inbox", |
10 | 10 | "build:docs:hypervisor": "documentation build ./index.js --github --shallow --sort-order source -f md > ./docs/hypervisor.md", |
11 | 11 | "build:docs:actor": "documentation build ./actor.js --github --shallow --sort-order source -f md > ./docs/actor.md", |
12 | 12 | "build:docs:capsStore": "documentation build ./capsStore.js --github --shallow --sort-order source -f md > ./docs/capsStore.md", |
13 | - "build:docs:scheduler": "documentation build ./scheduler.js --github --shallow --sort-order source -f md > ./docs/scheduler.md", | |
14 | - "build:docs:inbox": "documentation build ./inbox.js --github --shallow --sort-order source -f md > ./docs/inbox.md", | |
15 | 13 | "test": "node ./tests/index.js" |
16 | 14 | }, |
17 | 15 | "repository": { |
18 | 16 | "type": "git", |
@@ -30,8 +28,9 @@ | ||
30 | 28 | "author": "mjbecze <mjbecze@gmail.com>", |
31 | 29 | "contributors": "Alex Beregszaszi <alex@rtfs.hu>", |
32 | 30 | "license": "MPL-2.0", |
33 | 31 | "dependencies": { |
32 | + "binary-search": "^1.3.2", | |
34 | 33 | "binary-search-insert": "^1.0.3", |
35 | 34 | "buffer-pipe": "0.0.2", |
36 | 35 | "events": "^1.1.1", |
37 | 36 | "leb128": "0.0.4", |
scheduler.js | ||
---|---|---|
@@ -1,7 +1,6 @@ | ||
1 | 1 | const EventEmitter = require('events') |
2 | 2 | const binarySearchInsert = require('binary-search-insert') |
3 | -// const bs = require('binary-search') | |
4 | 3 | |
5 | 4 | // decides which message to go first |
6 | 5 | function comparator (messageA, messageB) { |
7 | 6 | // order by number of ticks if messages have different number of ticks |
@@ -22,31 +21,25 @@ | ||
22 | 21 | this.hypervisor = hypervisor |
23 | 22 | this._messages = [] |
24 | 23 | this._times = [] |
25 | 24 | this.actors = new Map() |
26 | - this._state = 'idle' | |
25 | + this._running = false | |
27 | 26 | } |
28 | 27 | |
29 | 28 | queue (messages) { |
30 | 29 | messages.forEach(msg => binarySearchInsert(this._messages, comparator, msg)) |
31 | - if (this._state === 'idle') { | |
32 | - this._state = 'running' | |
30 | + if (!this._running) { | |
31 | + this._running = true | |
33 | 32 | this._messageLoop() |
34 | 33 | } |
35 | 34 | } |
36 | 35 | |
37 | 36 | async _messageLoop () { |
38 | - let waits = [] | |
39 | 37 | while (this._messages.length) { |
40 | 38 | const message = this._messages.shift() |
41 | - waits.push(this._processMessage(message)) | |
42 | - const oldestMessage = this._messages[0] | |
43 | - if (!oldestMessage || oldestMessage._fromTicks !== message._fromTicks) { | |
44 | - await Promise.all(waits) | |
45 | - waits = [] | |
46 | - } | |
39 | + await this._processMessage(message) | |
47 | 40 | } |
48 | - this._state = 'idle' | |
41 | + this._running = false | |
49 | 42 | const promises = [] |
50 | 43 | this.actors.forEach(actor => promises.push(actor.shutdown())) |
51 | 44 | await Promise.all(promises) |
52 | 45 | this.actors.clear() |
@@ -54,18 +47,8 @@ | ||
54 | 47 | } |
55 | 48 | |
56 | 49 | // enable for concurrency |
57 | 50 | update (oldTicks, ticks) { |
58 | - // const index = bs(this._times, oldTicks, (a, b) => a - b) | |
59 | - // this._times.splice(index, 1) | |
60 | - // binarySearchInsert(this._times, (a, b) => { return a - b }, ticks) | |
61 | - // let oldestMessage = this._messages[0] | |
62 | - // const oldestTime = this._times[0] | |
63 | - // while (oldestMessage && oldestMessage._fromTicks < oldestTime) { | |
64 | - // const message = this._messages.shift() | |
65 | - // this._processMessage(message) | |
66 | - // oldestMessage = this._messages[0] | |
67 | - // } | |
68 | 51 | } |
69 | 52 | |
70 | 53 | async _processMessage (message) { |
71 | 54 | const to = message.funcRef.destId.toString('hex') |
Built with git-ssb-web