HTML and CSS Reference
In-Depth Information
}, false);
It uses a reference to the self object in order to add an event listener that listens for mes-
sages. When a message is received, the function passed in the second argument will be in-
voked (along with the message). The third parameter specifies whether the event needs to
be captured or not, if in doubt use false .
Let's now move the relevant code from tasks-controller.js to the Web Worker:
self.addEventListener('message', function(msg) {
var data = msg.data;
var lines = data.split('\n');
var tasks = [];
jQuery.each(lines, function(indx, val) {
if (indx >= 1 && val) {
var task = loadTask(val);
if (task) {
tasks.push(task);
}
}
});
self.postMessage(tasks);
}, false);
function loadTask(csvTask) {
var tokens = $.csv.toArray(csvTask);
if (tokens.length == 3) {
var task = {};
task.task = tokens[0];
task.requiredBy = tokens[1];
task.category = tokens[2];
return task;
}
return null;
}
Search WWH ::




Custom Search