How do I get the following code to call an asynchronous method properly?

problem description

function setupBridge (ctx, next) {

if (hasBootErrors(ctx)) {
  return next();
}
ctx.bridge = require("../plugins/bridge")(env);
if (ctx.bridge) {
  ctx.bridge.startEngine(ctx.entries);
}
next( );

}
ctx.bridge.startEngine (ctx.entries) cannot be executed properly, startEngine (ctx.entries) method cannot be found,
it is known that bridge.startEngine exists inside the asynchronous method

the environmental background of the problems and what methods you have tried

you can call

normally when the method is not asynchronous.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
called method:
async function create (env) {

var bridge = {};

var opts = await options (env);
var interval = opts.interval;

mostRecentRecord = new Date (). GetTime ()-opts.fetch.minutes * 60000

bridge.startEngine = function startEngine (entries) {

opts.callback = bridged(entries);

setInterval(function () {
  opts.fetch.minutes = parseInt((new Date() - mostRecentRecord) / 60000);
  opts.fetch.maxCount = parseInt((opts.fetch.minutes / 5) + 1);
  opts.firstFetchCount = opts.fetch.maxCount
  console.log("Fetching Share Data: ", "minutes", opts.fetch.minutes, "maxCount", opts.fetch.maxCount);
  engine(opts);
}, interval);

};
bridge.startEngine ();
return bridge;
}

what result do you expect? What is the error message actually seen?

I hope ctx.bridge.startEngine (ctx.entries) can execute

normally.
Jun.19,2022

put your

return Promise.resolve(bridge)

write to the callback of the asynchronous request

at the place of call

async function setupBridge (ctx, next) {

    if (hasBootErrors(ctx)) {
      return next();
    }
    ctx.bridge = require('../plugins/bridge')(env);
    if (ctx.bridge) {
      await ctx.bridge.startEngine(ctx.entries);
    }
    next( );
}
Menu