Reputation: 11830
I want to return an async function after 300ms.
In order to do that I thought about creating a promise which I resolve after 300 ms
const justLogDataFromForms = async (index, key, currentValue, payload) => {
const dummyPromise:Promise<any> = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 300);
});
await dummyPromise()
return
}
but this throws error
Type Promise have no call signatures.
Can someone explain me the error and let me know how I can fix it? Also, is there a better way to return an async function after x amount of time after it is called?
Upvotes: 0
Views: 11951
Reputation: 671
You can use
await Promise.all([dummyPromise]);
This should work in some case that really need Promise
as variable(s).
Upvotes: 0
Reputation: 23835
Your variable dummyPromise
is a Promise and not a Function so it can not be called. Just remove the parenthesis to await the Promise or don't use a variable at all:
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 300);
});
Upvotes: 2