summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/ErrorQueue.lua
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/scripts/lua/ErrorQueue.lua')
-rw-r--r--indra/newview/scripts/lua/ErrorQueue.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/ErrorQueue.lua b/indra/newview/scripts/lua/ErrorQueue.lua
new file mode 100644
index 0000000000..e6279f8411
--- /dev/null
+++ b/indra/newview/scripts/lua/ErrorQueue.lua
@@ -0,0 +1,32 @@
+-- ErrorQueue isa WaitQueue with the added feature that a producer can push an
+-- error through the queue. When that error is dequeued, the consumer will
+-- throw that error.
+
+local WaitQueue = require('WaitQueue')
+
+ErrorQueue = WaitQueue:new()
+
+function ErrorQueue:Enqueue(value)
+ -- normal value, not error
+ WaitQueue:Enqueue({ false, value })
+end
+
+function ErrorQueue:Error(message)
+ -- flag this entry as an error message
+ WaitQueue:Enqueue({ true, message })
+end
+
+function ErrorQueue:Dequeue()
+ local errflag, value = table.unpack(WaitQueue:Dequeue())
+ if errflag == nil then
+ -- queue has been closed, tell caller
+ return nil
+ end
+ if errflag then
+ -- 'value' is a message pushed by Error()
+ error(value)
+ end
+ return value
+end
+
+return ErrorQueue