DEV Community

ilya
ilya

Posted on

Is it possible to call one function continuously in while loop?

I am wondering whether it is possible or not to realize multi threads in javascript while loop.
for example,
`while(1){
sample(param1, param2)
}

function sample(param1, param2){
// some code here
console.log("some result")
}
`
I tried with it but it does not show console.log result.
I think it happens because while() call function again before the sample() function execute some code and so sample() function start from scratch again.
How can I realize multi thread in javascript?

Top comments (1)

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

JavaScript runs in a single thread. The V8 engine, however, provides worker threads. Read about it.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay