function WorkerScheduler() {
        var _tasks = {};
        self.onmessage = function(e) {
            var cmd = e.data;
            var id = _tasks[cmd.id];
            switch (cmd.type) {
                case 'setTimeout':
                    _tasks[cmd.id] = self.setTimeout(function() {
                        delete _tasks[cmd.id];
                        self.postMessage({
                            id: cmd.id
                        });
                    }, cmd.delay);
                    break;
                case 'clearTimeout':
                    delete _tasks[cmd.id];
                    if (id) {
                        self.clearTimeout(id);
                    }
                    break;
                default:
                    throw 'Unknown command ' + cmd.type;
            }
        };
    }
/**
     * The scheduler code that will run in the Worker.
     * Workers have a built-in `self` variable similar to `window`.
     */
The scheduler code that will run in the Worker.
Workers have a built-in `self` variable similar to `window`.
The scheduler code that will run in the Worker . Workers have a built - in ` self ` variable similar to ` window ` .
function WorkerScheduler() {
        var _tasks = {};
        self.onmessage = function(e) {
            var cmd = e.data;
            var id = _tasks[cmd.id];
            switch (cmd.type) {
                case 'setTimeout':
                    _tasks[cmd.id] = self.setTimeout(function() {
                        delete _tasks[cmd.id];
                        self.postMessage({
                            id: cmd.id
                        });
                    }, cmd.delay);
                    break;
                case 'clearTimeout':
                    delete _tasks[cmd.id];
                    if (id) {
                        self.clearTimeout(id);
                    }
                    break;
                default:
                    throw 'Unknown command ' + cmd.type;
            }
        };
    }
function WorkerScheduler ( ) { var _tasks = { } ; self . onmessage = function ( e ) { var cmd = e . data ; var id = _tasks [ cmd . id ] ; switch ( cmd . type ) { case 'setTimeout' : _tasks [ cmd . id ] = self . setTimeout ( function ( ) { delete _tasks [ cmd . id ] ; self . postMessage ( { id : cmd . id } ) ; } , cmd . delay ) ; break ; case 'clearTimeout' : delete _tasks [ cmd . id ] ; if ( id ) { self . clearTimeout ( id ) ; } break ; default : throw 'Unknown command ' + cmd . type ; } } ; }
The scheduler code that will run in the Worker.
The scheduler code that will run in the Worker .