The Promise executor function is called synchronously by the Promise constructor.
If an async function is used as a Promise executor, thrown errors will not be caught by the Promise and will instead result in unhandled rejections.
Additionally, if a Promise executor function is using await, there’s probably no need to use the new Promise constructor - you can return the awaited value or use the Promise directly.
new <unknown>(executor:(resolve:(value:unknown)=>void, reject:(reason?:any)=>void)=>void)=>Promise<unknown>
Creates a new Promise.
@param ― executor A callback used to initialize the promise. This callback is passed two arguments:
a resolve callback used to resolve the promise with a value or the result of another promise,
and a reject callback used to reject the promise with a provided reason or error.
new <unknown>(executor:(resolve:(value:unknown)=>void, reject:(reason?:any)=>void)=>void)=>Promise<unknown>
Creates a new Promise.
@param ― executor A callback used to initialize the promise. This callback is passed two arguments:
a resolve callback used to resolve the promise with a value or the result of another promise,
and a reject callback used to reject the promise with a provided reason or error.
Promise(asyncfunction(
resolve: (value:unknown)=>void
resolve,
reject: (reason?:any)=>void
reject) {
try {
resolve: (value:unknown)=>void
resolve(await
const asyncOperation:any
asyncOperation());
} catch (
function(localvar)error: unknown
error) {
reject: (reason?:any)=>void
reject(
function(localvar)error: unknown
error);
}
});
const
const result:Promise<unknown>
result = new
var Promise:PromiseConstructor
new <unknown>(executor:(resolve:(value:unknown)=>void, reject:(reason?:any)=>void)=>void)=>Promise<unknown>
Creates a new Promise.
@param ― executor A callback used to initialize the promise. This callback is passed two arguments:
a resolve callback used to resolve the promise with a value or the result of another promise,
and a reject callback used to reject the promise with a provided reason or error.