-2

is there any way to create new process and make it execute some code while main process execute some code too. in my code,i used something like this:

<script>
function f1(){//some code
}
setTimeout(f1,delay);
</script>

my question is: the main process execute f1 function or a new one?,and if it is the main how can i execute f1 function with a new process.

i had tried setTimeout function and i see that the main process execute the function after a delay time.

any help please.

phoenix
  • 351
  • 4
  • 11
  • Do you have to use script in browser of some other environment would do? Either regular Windows CScript host or NodeJS let you do that (i.e. http://stackoverflow.com/questions/11876281/start-new-process-on-nodejs) – Alexei Levenkov Oct 24 '16 at 18:23
  • JS is single threaded, and event driven. You should say what you want to achieve if you want more help – Simon H Oct 24 '16 at 18:23
  • JS is no longer single threaded, but you certainly don't have control over multiple processes from the browser (node has the cluster module which can handle that). Looking up *any* articles on multi-threaded JS would lead OP to web workers, which should lead to a solution. – ssube Oct 24 '16 at 18:24
  • @SimonH https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers ... – Alexei Levenkov Oct 24 '16 at 18:24
  • 2
    Side note: "with new process like using new thread in java" - Java does not use processes to start new threads... So maybe starting new process is not what you are looking for... – Alexei Levenkov Oct 24 '16 at 18:27
  • Difficult to tell if you want to create an instance object, Promises, event management or something else. Please clarify your intent. – Mark Schultheiss Oct 24 '16 at 18:34

1 Answers1

1

Threads and processes are two different things.

Until recently JavaScript had neither. You could emulate multi-threading using a timeout of 0. You can still do that.

For true multi-threading now you can use Web Workers. I don't think you can have multiple process except if you are using some plugin (Java Applets for example).

Just search in Wikipedia for thread, process and WebWorkers.

BCartolo
  • 720
  • 4
  • 21
  • why they reduce my reputation,i understand this Incorrectly and now i learn what it is,please delete your answer to make me delete my question – phoenix Oct 24 '16 at 18:35