Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed asynchronous code features #25

Open
BanDroid opened this issue Dec 31, 2022 · 6 comments
Open

Delayed asynchronous code features #25

BanDroid opened this issue Dec 31, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@BanDroid
Copy link

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);
@Jaagrav
Copy link
Owner

Jaagrav commented Dec 31, 2022

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.

@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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.

@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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.

@BanDroid
Copy link
Author

BanDroid commented Jan 1, 2023

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...

@Jaagrav Jaagrav added the enhancement New feature or request label Jan 1, 2023
@Jaagrav
Copy link
Owner

Jaagrav commented Jan 1, 2023

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.

@BanDroid
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants