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.