How to get id of current stream in javascript / jquery

I am new to javascript / jquery. I have a simple question that one of the java script functions is running and wants to see the thread id for this thread. In java we like

Thread.getID();//in java

which will print the thread id of the running thread. Similarly, what is the function we use to get the id of the current stream in javscript.

I really want to ...

In my JavaScript, I have a listener that listens to the channel. When a message appears in the channel, the callback method is called and processes the data. Therefore, I am trying to understand how this works. Let them say that there are 10 messages in the channel, and for each message a callback is called.

Suppose the callback method works for message "a", and while processing data for message "a", he received another message "b". Will the callback method for "b" be called after processing for message "a" has finished?

I wanted to check this by typing the thread number in a callback function that tells whether it is executed sequentially (single thread) or multiple threads. This is why I tried to print the stream id. Thank you for your responses.

Thanks Swati

+4
source share
4 answers

JavaScript is single threaded. Therefore, this does not apply to JavaScript.

However, you can create multiple threads through the very limited Worker interface introduced in HTML5 and is already available in some browsers. From an MDC article ,

The Worker interface creates real OS-level threads , and concurrency can cause interesting effects in your code if you are not careful. However, in the case of web workers, carefully controlled communication points with other threads mean that it is actually very difficult to cause concurrency problems. There is no access to non-stream components or to the DOM, and you need to pass specific data to and from the stream through serialized objects. Therefore, you have to work very hard to create problems in your code.

Why do you need this?

+3
source

For most things, JavaScript has a single thread, so there is no method for this, since it would be immutable with "1", where you could access such information. There are more threads in the background for events and queues (handled by the browser), but there is a main thread for your code.

Java! = JavaScript, they only have four letters :)

0
source

Apart from the name, Javascript is completely unrelated to Java. Javascript has no threads that you can access.

0
source

In javascript, scripts are run in the browser stream, and your code does not have access to this information, in fact, your code has no idea how it is executed. Then no! there is no such thing in javascript.

0
source

All Articles