How to get WebWorker instance from inside?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

Playing boules... IN SPACE!

Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?

What percentage of the mass/energy of the universe is in the form of electromagnetic waves?

Given a specific computer system, is it possible to estimate the actual precise run time of a piece of Assembly code

In chocolate terminology, what is the name of thinly sliced leaf-shaped toppings made from hot, smooth chocolate, used to form flower petals?

Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?

Using GNU screen, I get raw prompt with backslashes

Are manifolds admitting a circle foliation covered by manifolds with a (non-trivial) circle action?

How can I oppose my advisor granting gift authorship to a collaborator?

Divide Numbers by 0

Design of 50 ohms RF trace for 2.4GHz...Double layer FR-4 PCB

Order by inside subquery

Meaning of "educating the ice"

Can my UK debt be collected because I have to return to US?

Map a function that takes arguments in different levels of a list

How to check status of Wi-Fi adapter through command line?

Does secure hashing imply secure symmetric encryption?

Received email from ISP saying one of my devices has malware

How do I stop making people jump at home and at work?

Unkown DIP IC (OP277PA)

garage light with two hots and one neutral

Why KVM VPS is slower then OPENVZ

When making yogurt, why doesn't bad bacteria grow as well?

Why didn't Thatcher give Hong Kong to Taiwan?



How to get WebWorker instance from inside?


How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have created a web worker using, but I could not find a way to get the instance of Worker from inside the Worker function.



From inside the function, if I use 'this' or 'self' then I only can get 'DedicatedWorkerGlobalScope' object.



Please see the code snippet below to understand the problem:






/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





I have tried to pass the Worker instance in postMessage, such as:






// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.





Thanks in advance for the help~










share|improve this question
























  • What do you need it for?

    – charlietfl
    Mar 28 at 1:59











  • I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

    – hmaxf2
    Mar 28 at 8:45












  • So why can't that be done using standard messages and some sort of state object?

    – charlietfl
    Mar 28 at 9:07












  • The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

    – hmaxf2
    Mar 29 at 4:26

















1















I have created a web worker using, but I could not find a way to get the instance of Worker from inside the Worker function.



From inside the function, if I use 'this' or 'self' then I only can get 'DedicatedWorkerGlobalScope' object.



Please see the code snippet below to understand the problem:






/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





I have tried to pass the Worker instance in postMessage, such as:






// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.





Thanks in advance for the help~










share|improve this question
























  • What do you need it for?

    – charlietfl
    Mar 28 at 1:59











  • I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

    – hmaxf2
    Mar 28 at 8:45












  • So why can't that be done using standard messages and some sort of state object?

    – charlietfl
    Mar 28 at 9:07












  • The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

    – hmaxf2
    Mar 29 at 4:26













1












1








1








I have created a web worker using, but I could not find a way to get the instance of Worker from inside the Worker function.



From inside the function, if I use 'this' or 'self' then I only can get 'DedicatedWorkerGlobalScope' object.



Please see the code snippet below to understand the problem:






/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





I have tried to pass the Worker instance in postMessage, such as:






// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.





Thanks in advance for the help~










share|improve this question














I have created a web worker using, but I could not find a way to get the instance of Worker from inside the Worker function.



From inside the function, if I use 'this' or 'self' then I only can get 'DedicatedWorkerGlobalScope' object.



Please see the code snippet below to understand the problem:






/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





I have tried to pass the Worker instance in postMessage, such as:






// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.





Thanks in advance for the help~






/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





/******** below is main.html file *********/
var mywebworker1 = new Worker('mywebworker1.js');

// register event listener to receive data from worker
mywebworker1.addEventListener('message', function(e)
// at this point, 'this' == 'Worker' instance

// ... other code
);


/******** below is inside mywebworker1.js file *********/
self.addEventListener('message', function(e)
// at this point, 'this' == 'DedicatedWorkerGlobalScope' object

// PROBLEM: How to get 'Worker' instance in here ??

// .. other code
, false);





// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.





// send command to start counting
mywebworker1.postMessage("action": "count", "from" : 7, "to": 22, "instance": mywebworker1);

// GOT ERROR message = Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Worker object could not be cloned.






javascript web-worker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 1:46









hmaxf2hmaxf2

3862 silver badges9 bronze badges




3862 silver badges9 bronze badges















  • What do you need it for?

    – charlietfl
    Mar 28 at 1:59











  • I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

    – hmaxf2
    Mar 28 at 8:45












  • So why can't that be done using standard messages and some sort of state object?

    – charlietfl
    Mar 28 at 9:07












  • The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

    – hmaxf2
    Mar 29 at 4:26

















  • What do you need it for?

    – charlietfl
    Mar 28 at 1:59











  • I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

    – hmaxf2
    Mar 28 at 8:45












  • So why can't that be done using standard messages and some sort of state object?

    – charlietfl
    Mar 28 at 9:07












  • The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

    – hmaxf2
    Mar 29 at 4:26
















What do you need it for?

– charlietfl
Mar 28 at 1:59





What do you need it for?

– charlietfl
Mar 28 at 1:59













I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

– hmaxf2
Mar 28 at 8:45






I have a need to set/add 'some states' into the 'Worker' object, so caller and other functions can see the state. For example: is it busy ? is it finished ? what is the current progress ?

– hmaxf2
Mar 28 at 8:45














So why can't that be done using standard messages and some sort of state object?

– charlietfl
Mar 28 at 9:07






So why can't that be done using standard messages and some sort of state object?

– charlietfl
Mar 28 at 9:07














The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

– hmaxf2
Mar 29 at 4:26





The above snippet is only an example, the actual code is quite broad and the Worker states will be shared among different function, so I feel need the add some flags directly to the Worker object itself instead of making some global variables and doing many postMessage(), do you have any way to get the Worker object instance from inside the Worker itself ?

– hmaxf2
Mar 29 at 4:26












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388992%2fhow-to-get-webworker-instance-from-inside%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388992%2fhow-to-get-webworker-instance-from-inside%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript