var start;
onmessage = getStart;
function getStart(event) {
	start = 1*event.data;
	onmessage = getEnd;
}
var end;
function getEnd(event) {
	end = 1*event.data;
	onmessage = null;
	work();
}
function work() {
	var result = 0;
	for (var i = start; i < end; i += 1) {
		// perform some complex calculation here
		result += 2;
	}
	postMessage(result);
}