git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: ee2ec06375d8aa1dbc04ba175e9de5085bfa8c42

Files: ee2ec06375d8aa1dbc04ba175e9de5085bfa8c42 / port.js

797 bytesRaw
1module.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 (name) {
8 this._queue = []
9 this.ticks = 0
10 this.name = name
11 }
12
13 /**
14 * queues a message on the port
15 * @param {Message}
16 */
17 queue (message) {
18 this.ticks = message._fromPortTicks
19 this._queue.push(message)
20 }
21
22 /**
23 * returns the message at the front of the queue
24 * @returns {Message}
25 */
26 peek () {
27 return this._queue[0]
28 }
29
30 /**
31 * dequeue a message
32 * @returns {Message}
33 */
34 dequeue () {
35 return this._queue.shift()
36 }
37
38 /**
39 * returns the size of the queue
40 * @returns {Integer}
41 */
42 get size () {
43 return this._queue.length
44 }
45}
46

Built with git-ssb-web