How do one change the following promise function into a async function.
const createRecord = (record) =>{
return new Promise((resolve)=>{
queue.push({
id: Math.floor(Math.random()*100),
callback: (id)=>{resolve(id);},
data: record
});
});
};
I've tried the following code, but the function completes before the callback completes.
const createRecord = async (record) =>{
queue.push({
id: Math.floor(Math.random()*100),
callback: (id)=>{return id;},
data: record
});
};
The callback is initiated by the following interval method;
var queue = [];
setInterval(() => {
queue.forEach((record)=>{
record.callback(record.id);
});
}, 2000);