Here is what I want to do:
Promise.all([aurelia.start(), entityManagerProvider.initialize()]) .then((results:Array<any>) => { let aurelia: any = results[0]; aurelia.setRoot(); });
aurelia.start()
returns an Aurelia type, while initialize()
returns void.
The compiler gives an error message that the type cannot be inferred from the usage.
What I am trying to achieve is to get them to run at the same time, as they are both very long processes, then run Aurelia.setRoot();
Introduction to TypeScript promise. The promise in TypeScript is used to make asynchronous programming. The promise can be used when we want to handle multiple tasks at the same time. By the use of TypeScript promise, we can skip the current operation and move to the next line of the code.
all() The Promise. all() method takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises. This returned promise will fulfill when all of the input's promises have fulfilled, or if the input iterable contains no promises.
Any async promise-based function can have await in front of it to stop your code on that line until the promise is fulfilled, then return the result. Any function that returns a Promise, including web API calls, can be called using await.
Its generally best to have arrays with consistent types. You can do the following manually though (passing in generic arguments):
Promise.all<Aurelia, void>( [aurelia.start(), entityManagerProvider.initialize() ]) .then(results => { let aurelia = results[0]; aurelia.setRoot(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With