git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e62cd9ffb288088f86f5a80cfd7f8e5dc58a6b5c

updated getnextmessage to check if currently getting next message

wanderer committed on 12/12/2017, 12:47:36 AM
Parent: 3146cb3249c2ab000ed44d4712910ff42fd0d5c1

Files changed

actor.jschanged
inbox.jschanged
actor.jsView
@@ -67,9 +67,9 @@
6767 // this ensure we only every have one loop running at a time
6868 if (!this.running) {
6969 this.running = true
7070 while (1) {
71- const message = await this.inbox.nextMessage()
71+ const message = await this.inbox.nextMessage(0, true)
7272 if (!message) break
7373
7474 // run the next message
7575 await this.runMessage(message)
inbox.jsView
@@ -52,11 +52,8 @@
5252 * @param {Integer} timeout
5353 * @returns {Promise}
5454 */
5555 async nextTaggedMessage (tags, timeout) {
56- if (this._waitingTags) {
57- throw new Error('already waiting on tags')
58- }
5956 this._waitingTags = new Set(tags)
6057 this._queue = this._queue.filter(message => !this._queueTaggedMessage(message))
6158
6259 // todo: add saturation test
@@ -72,16 +69,18 @@
7269 * Waits for the the next message if any
7370 * @param {Integer} timeout
7471 * @returns {Promise}
7572 */
76- nextMessage (timeout) {
73+ nextMessage (timeout, getCurrent = false) {
7774 if (!this._gettingNextMessage) {
7875 this._gettingNextMessage = this._nextMessage(timeout)
76+ } else if (!getCurrent) {
77+ throw new Error('already waiting for next message')
7978 }
8079 return this._gettingNextMessage
8180 }
8281
83- async _nextMessage (timeout = 0) {
82+ async _nextMessage (timeout) {
8483 await Promise.all([...this.actor._sending.values()])
8584 let message = this._getOldestMessage()
8685 if (message === undefined && timeout === 0) {
8786 return

Built with git-ssb-web