Skip to content

Commit

Permalink
Change handling of callback return value, handle promise
Browse files Browse the repository at this point in the history
In case that the resulting return value of the callback argument is a promise, then it will be returned. Otherwise, if other kind of return value will simply be ignored.
  • Loading branch information
aedart committed Sep 28, 2024
1 parent 69423ab commit c6d2849
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BootError
} from "@aedart/support/services";
import { isset } from "@aedart/support/misc";
import { isPromise } from "@aedart/support/reflections";
import LoadEnvironmentVariables from "./bootstrap/LoadEnvironmentVariables";
import SetupFacades from "./bootstrap/SetupFacades";
import { version } from "../package.json";
Expand Down Expand Up @@ -420,11 +421,15 @@ export default class Application extends Container implements ApplicationContrac
// Change "running" state,...
this.runTriggered = true;

// If a callback has been provided, invoke it. If the callback returns a promise, resolve it.
// If a callback has been provided, invoke it.
if (isset(callback)) {
const result = this.call(callback as Callback | CallbackWrapper | ClassMethodReference);

return Promise.resolve(result);
// In case that the call results in a promise, then return it. Otherwise, any evt. return
// value is just ignored.
if (isPromise(result)) {
return result;
}
}

return Promise.resolve(true);
Expand Down

0 comments on commit c6d2849

Please sign in to comment.