Git Product home page Git Product logo

vkthread's People

Contributors

vkiryukhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vkthread's Issues

Passing Javascript Obj as argument(s)

Hi,

I was just trying your nice piece of work, and I got into this:

TypeError: Converting circular structure to JSON
at Object.stringify (native)
at Object.JSONfn.stringify (http://rails.lan:5000/libs/vkthread/0.51.00/vkthread.js:32:15)

... while passing javascript Obj as arguments of a function. Is it even possibile in the first place? Everything works as expected passing numeric values.

Thanks,
Luca

Using XMLHttpRequest with vkthread

Hi,

I wonder if it is possible to do AJAX calls with vkthread?

(With vanilla Worker, I can do postMessage inside the onreadystatechange handler, I'm not sure if it is possible to do something similar with this library.)

Thanks!

how to use external functions in threaded function?

hello,
thanks for this awesome library, i have some work defined as :

function bytesToSize(bytes) {
            var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
            if (bytes == 0) return '0 Byte';
            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
            return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
        };
        function computeCompletionSize(taskList) {
            var totalSize = doneSize = 0;
            for (var i = 0; i < taskList.length; i++) {
                console.log(taskList[i].taskFileSize);
                totalSize +=taskList[i].taskFileSize;
                //done size
                if (taskList[i].taskPercent === 100) {
                    doneSize += taskList[i].taskFileSize;
                    var elem = document.getElementById(taskList[i].taskId);
                    elem.parentNode.removeChild(elem);
                }
            }
            console.log(bytesToSize(doneSize) + " /" + bytesToSize(totalSize));
            return bytesToSize(doneSize) + " /" + bytesToSize(totalSize);
        }

called from:

var param = {
                    fn: computeCompletionSize,     // <-- function to run in a thread;
                    args: [taskList] // <-- function's arguments;
                };
                vkthread.exec(param).then(function (data) {
                    document.getElementById("prgsize").innerText = data;
                });

now i suppose the reason for error bytesToSize func not defined is due to it being on another thread, can you tell me how i can put this or call in same context/thread so it starts working without my code loosing modularity.
thanks

Integrate the plugin

Hi , i need to ask you
how i can integrate it with my project

i added the package file (vkThread) but when i attempt to execute any method , it show me an exception
that Promise isn't defined!

Not work with file:// protocol

this.path = 'http'+ err.split('http')[1].split('vkthread.js').slice(0,-1) + 'worker.js';

It's code not work for url with file:// protocol.

cannot pass objects with the string "function" as a value

If you pass an object like the following

{
"name":"function",
"args":[]
}

through JSONfn.stringify and JSONfn.parse you will get a syntax error because it will try and eval the string "function" which will error.

updating JSONfn in vkthread.js

var JSONfn = {

/* this is a fragment of JSONfn plugin ( https://github.com/vkiryukhin/jsonfn ) */

stringify:function (obj) {
  return JSON.stringify(obj, function (key, value) {
    if (value instanceof Function || typeof value == 'function') {
      return '_nOiTcNuf_' + value.toString();
    }
    if (value instanceof RegExp) {
      return '_PxEgEr_' + value;
    }
    return value;
  });
}

};

and JSONfn in worker.js

var JSONfn = {
parse:function (str, date2obj) {
var iso8061 = date2obj ? /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:.\d*)?)Z$/ : false;
return JSON.parse(str, function (key, value) {
if (typeof value != 'string') return value;
if (value.length < 8) return value;
if (iso8061 && value.match(iso8061)) return new Date(value);
if (value.substring(0, 10) === 'nOiTcNuf') return eval('(' + value.slice(10) + ')');
if (value.substring(0, 8) === 'PxEgEr') return eval(value.slice(8));
return value;
});
}
};

like this negates the problem.

Release on npm

Feature Request

Problem:

Drop all bower usage in dev-environment to unify and simplify dependency management for developers by receiving all packages using npm/yarn.

Solution:

Would you mind publishing the package on npm? I wouldn't mind doing or managing updates and releases myself - but have no previous expertise on this - and npm terms state you mustn't confuse people about the authorship of the package. I think would you have to register and npm account, reference the original repo first - afterwards i think releasing versions etc. would be possible by pull request.

Tasks:

  • Register npm account
  • Register package
  • Release initial version

This doesn’t work with recursive functions.

Json.stringify throw an error when the function callsvkthread.execrecursively :

<script>
var recursionLevel=0;
var maxthreads=0;
var recursion = function(obj){
  for(var b in obj) { 
    if(typeof obj.hasOwnProperty !== 'undefined' && obj.hasOwnProperty(b)){
      if(typeof obj[b] === "string" && obj[b].indexOf("domains.google") == -1 && obj[b].indexOf("googrz.co.nz")>-1){
    alert(obj);
        obj[b] = obj[b].replace("googrz.co.nz", "googrz.co.in");
      }else if(typeof obj[b] === "object" && obj[b] && recursionLevel<150){ // call as an object "recursively"
        recursionLevel++;
        if(maxthreads<8) {
           maxthreads++;
           vkthread.exec(recursion,[obj[b]],function(data){maxthreads--;})
         } else
           recursion(obj[b]);
        recursionLevel--;
      }
    }
  }
}
recursion(window);
</script>

Multiple contexts support

Hello!
Great library!

I have a quick question: does your library support multiple contexts?

Playing with your simple example, is there a way to make something like this work?

function Demo(str, max){
	this.str = str;
	this.max = max;
}
Demo.prototype.foo = function(){
	var ret, ix;
	for(ix=0;ix<this.max;ix++){
		ret = this.str.split(',').join('-');
	}
	return ret;
};
function Act(obj1,obj2){
  this.obj1 = obj1;
  this.obj2 = obj2;
}
Act.prototype.bar = function(){
   return String(this.obj1.max+this.obj1.max) + String(this.obj2.foo()) + String(this.obj1.foo()); // could be more complicated
};


var myDemo1 = new Demo('aaa,bbb,ccc',7e5);
var myDemo2 = new Demo('123,456,789',5);

var myAct = new Act(myDemo1,myDemo2);

var param = {
	    fn: myAct.bar,
	    context: myAct
    };

vkthread.exec(param).then(
    function(data){
	    console.log(data);
    }
);

( Does not work like this, see fiddle )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.