Delayed asynchronous code features
Is there a way to work with asynchronous code that have delay? For example, setTimeout() in javascript.
If i made a code inside the timeout and make the delay to be 2 seconds, all of the code just executed. Here is example code
console.log("before timeout");
setTimeout(() => {
console.log("inside timeout");
}, 2000);
Hey this looks like a question that you'd want to ask in discussion but anyway to answer your question, you can always use Promise in order to make your code execute asynchronously, here's how you can do so.
const myFunc = async () => {
console.log("before timeout");
await new Promise((resolve) => {
setTimeout(resolve, 2000);
});
console.log("after timeout");
}
myFunc();
This code, in simple words, pauses execution for 2 seconds before moving on. You can read more on async-await and promises here.
Please close this issue if your query is answered.
Hey this looks like a question that you'd want to ask in discussion but anyway to answer your question, you can always use Promise in order to make your code execute asynchronously, here's how you can do so.
const myFunc = async () => { console.log("before timeout"); await new Promise((resolve) => { setTimeout(resolve, 2000); }); console.log("after timeout"); } myFunc();This code, in simple words, pauses execution for 2 seconds before moving on. You can read more on async-await and promises here.
Please close this issue if your query is answered.
Sorry, this doesn't answer my question. I know it will pause the execution for specified time, but what i'm asking for the feature is on displaying the code that is not delayed first, and then after that specified time, it execute the code inside asynchronous code.
In your code example, "before timeout" will displayed at the same time with the code inside setTimeout().
I'm hoping there will be a indicator in the response if the code finally executed, still executed, or error when executing.
For example
{
"timestamp": 16792938484,
"status": 200,
"output": "still executing the asynchronous code",
"error": "",
"language": "js",
"info": "v16",
"compilerStatus": "onProgress"
}
And then when the async code finishes, will display different response
{
"timestamp": 16792938484,
"status": 200,
"output": "this output is from async code",
"error": "",
"language": "js",
"info": "v16",
"compilerStatus": "onFinished"
}
I'm taking this inspiration from AssemblyAI on how they give a key status in the response, the value could be queued and finish so it could be determined if the process still going or not.
You could make this the same if you 're giving each request an ID, and process the code temporary using that ID.
In javascript, if there's a line that causing errors, it still execute the code anyway.
console.log("this is working code");
console.log("this is error code);
The output will be
this is working code
SyntaxError: error messages here...
This is a good feature idea, you can work on this if you want to, cause I got exams next week and can't promise to get it up and working soon.
This is a good feature idea, you can work on this if you want to, cause I got exams next week and can't promise to get it up and working soon.
Sorry for long response, i dont have docker installed yet. Currently i'm trying to resolve this problem.
It seems you split it only by \n for each input, but it doesn't work for numbers and strings input together, i will try to use node to run this. Basically because my skills aren't for this kind of big project, but i will try my best to code clean.