-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to access outside function from hamsters.run #37
Comments
@darkworks Thanks for using the library however please in the future please follow the provided issue template when submitting tickets, it makes it much easier for me to keep track of them down the road. The issue you are facing is that threads are sandboxed environments so you cannot share scope with the main thread, I know this is counter intuitive at first but it's actually a good thing in the sense of thread safety and ensuring parallel tasks don't conflict with one another. This will change somewhat down the road as JavaScript adds support for Atomic operations for now though you have a few options to accomplish what you want here. You can either do the following and simply make your function testFun and modify the inside of testFun to make use of the internal params object. this.testfun = function(val) {
// do something and return using params and rtn.data
};
hamsters.run(params, testFun, function(output) {
console.log(output);
}, hamsters.maxThreads, true); Or you can just define testFun inside your hamsters function. hamsters.run(params, function() {
var testfun = function(val) {
// do something and return
};
rtn.data.push(testFun(value));
}, function(output) {
console.log(output);
}, hamsters.maxThreads, true); |
Take a look at the logic from lzwFloss for an example of how you can define functions to be used within hamsters. https://github.com/austinksmith/lzwFloss.js/blob/master/lzwFloss.js |
thanks :) to pass function body in text in paramas and it worked :) example :
|
Closing this issue, thanks @darkworks |
hi am processing canvas large data so to speedup things am trying to use hamsters for the first time
so my question is that my outside functions are not accessible within hamsters.run
example
thanks
The text was updated successfully, but these errors were encountered: