From: Darren <darren@darrenwhitlen.com>
Date: Sat, 18 Oct 2014 01:02:08 +0000 (+0100)
Subject: Re-implementing PluginInterface event.wait
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=525f5dd460b12fe77509d2b3377248734f7ca1bf;p=KiwiIRC.git

Re-implementing PluginInterface event.wait
---

diff --git a/server/plugininterface.js b/server/plugininterface.js
index d74ec6c..e9ec2f9 100644
--- a/server/plugininterface.js
+++ b/server/plugininterface.js
@@ -72,16 +72,23 @@ PluginInterface.prototype.emit = function emit(type, data) {
                     var event_data = {
                         callback: function () {
                             resolve(data);
+                            event_data.callback = null;
                         },
                         preventDefault: function (reason) {
                             rejected = true;
                             if (reason) {
                                 rejected_reasons.push(reason);
                             }
-                        }
+                        },
+                        wait: false
                     };
 
                     listener(event_data, data);
+
+                    // If the module has not specified that we should wait, callback now
+                    if (!event_data.wait && event_data.callback) {
+                        event_data.callback();
+                    }
                 });
             });
         }, Promise.resolve(data));