Skip to content

Commit

Permalink
fix: add context to event listener aiife
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Aug 9, 2024
1 parent 2898ff6 commit 3f07ead
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/backend/src/services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -82,7 +83,7 @@ class EventService extends BaseService {
alarm: true,
});
}
})();
});
}

}
Expand Down
3 changes: 3 additions & 0 deletions src/backend/src/util/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 3f07ead

Please sign in to comment.