Files: 42bb5a2f36de56726c4bd6ede09c95352d5b545d / port.js
772 bytesRaw
1 | module.exports = class Port { |
2 | /** |
3 | * a simple repsentation of a port |
4 | * @property {Interger} ticks - the last know number of ticks the |
5 | * corrisponding container is at |
6 | */ |
7 | constructor () { |
8 | this._queue = [] |
9 | this.ticks = 0 |
10 | } |
11 | |
12 | /** |
13 | * queues a message on the port |
14 | * @param {Message} |
15 | */ |
16 | queue (message) { |
17 | this.ticks = message._fromPortTicks |
18 | this._queue.push(message) |
19 | } |
20 | |
21 | /** |
22 | * returns the message at the front of the queue |
23 | * @returns {Message} |
24 | */ |
25 | peek () { |
26 | return this._queue[0] |
27 | } |
28 | |
29 | /** |
30 | * dequeue a message |
31 | * @returns {Message} |
32 | */ |
33 | dequeue () { |
34 | return this._queue.shift() |
35 | } |
36 | |
37 | /** |
38 | * returns the size of the queue |
39 | * @returns {Integer} |
40 | */ |
41 | get size () { |
42 | return this._queue.length |
43 | } |
44 | } |
45 |
Built with git-ssb-web