Comments (4)
Closing this issue, thanks @darkworks
from hamsters.js.
@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);
from hamsters.js.
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
from hamsters.js.
thanks :)
hmmm i used this : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
to pass function body in text in paramas and it worked :)
example :
var params = {
addfun : 'return a+b',
};
hamsters.run(params, function() {
var addfun = new Function('a','b',params.addfun);
// now addfun can be used inside.
};
from hamsters.js.
Related Issues (20)
- Uncaught ReferenceError: adTestentListener is not defined HOT 1
- Tests not pasing HOT 1
- React-native android side, typeerror using hamsters and react-native-threads HOT 18
- how to migrate from v4 to v5 HOT 18
- Promises error HOT 15
- rtn data is pushed on different index than 0 HOT 19
- Windows 10 | Node.js - no output when using hamsters.js + webworker-threads package HOT 13
- The examples in the website don't have the source code of the example HOT 2
- Cannot read property 'buffer' of undefined." HOT 4
- im not getting correct results from the rtn.data object in hamsterjs v5.1.3 HOT 21
- Pointers for use with ReactJS HOT 2
- react-native-threads not working. HOT 2
- react native workers HOT 4
- ERROR: while initiating hamsters.js [React Native] HOT 5
- Your country is blocked from accessing this content. HOT 1
- http://www.hamsters.io/ offline HOT 2
- Anyone use hamesters.js successfully in Chrome Browser ? HOT 3
- Uncaught TypeError: hamsters.run is not a function HOT 3
- rtn undefined HOT 4
- react-native-hamsters/example - undefined is not an object (evaluating 'message.data.data') HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamsters.js.