fix: add context to event listener aiife

This commit is contained in:
KernelDeimos 2024-08-09 16:50:39 -04:00
parent 2898ff681f
commit 3f07ead1b9
2 changed files with 8 additions and 4 deletions

View File

@ -16,6 +16,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { Context } = require("../util/context");
const BaseService = require("./BaseService");
class ScopedEventBus {
@ -55,7 +56,7 @@ class EventService extends BaseService {
// IIAFE wrapper to catch errors without blocking
// event dispatch.
(async () => {
Context.arun(async () => {
try {
await callback(key, data, meta);
} catch (e) {
@ -65,14 +66,14 @@ class EventService extends BaseService {
alarm: true,
});
}
})();
});
}
}
for ( const callback of this.global_listeners_ ) {
// IIAFE wrapper to catch errors without blocking
// event dispatch.
(async () => {
Context.arun(async () => {
try {
await callback(key, data, meta);
} catch (e) {
@ -82,7 +83,7 @@ class EventService extends BaseService {
alarm: true,
});
}
})();
});
}
}

View File

@ -60,6 +60,9 @@ class Context {
static describe () {
return this.get().describe();
}
static arun (cb) {
return this.get().arun(cb);
}
get (k) {
return this.values_[k];
}