Execute Background Task In Javascript

后端 未结 9 1611
迷失自我
迷失自我 2020-11-28 22:39

I have a cpu intensive task that I need to run on the client. Ideally, I\'d like to be able to invoke the function and trigger progress events using jquery so I can update

9条回答
  •  萌比男神i
    2020-11-28 23:26

    Here is my solution to the problem, in case someone wants simple copy-pasteable piece of code:

        var iterate = function (from, to, action, complete) {
            var i = from;
            var impl = function () {
                action(i);
                i++;
                if (i < to) setTimeout(impl, 1);
                else complete();
            };
            impl();
        };
    

提交回复
热议问题