<commit_before>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global define: false, console: false, window: false, setTimeout: false */

define( function ( require ) {
    
    var lang = require( 'lang' );
    var Delegate = require( 'common/delegate' );
    var Task = require( './task' );
    var Timer = require( './timer' );
    var Graph = require( 'common/graph' );
    var phases = require( 'core/scheduler-phases' );
    
    var Scheduler = function( options ) {
        
        options = options || {};
        
        var _tasks = {},
            _phases = {};
        
        for( var phase in phases ) {
            _phases[phases[phase]] = new Graph();
        }
        
        var _running = false,
            that = this,              
            _previousTime,
            _schedule,
            _tick = new Delegate();    // Time signal, sent each frame
        
        this.Timer = Timer({ tick: _tick });        
        this.Task = Task({ manager: this });
        
        Object.defineProperty( this, 'phases', {
           get: function() {
               return phases;
           } 
        });

        var _realTime = new this.Timer();
        Object.defineProperty( this, 'realTime', {
            get: function() {
                return _realTime;
            }
        });
        
        var _simulationTime = new this.Timer();
        Object.defineProperty( this, 'simulationTime', {
            get: function() {
                return _simulationTime;
            }
        });
        
        var _frame = 0;
        Object.defineProperty( this, 'frame', {
            get: function() {
                return _frame;
            }
        });
        
        var _active = false;
        Object.defineProperty( this, 'active', {
            get: function() {
                return _active;
            }
        });
              
        this.suspend = function() {
            _active = false;
        };
        
        this.clear = function() {
            _tasks = {};
        };
        
        this.resume = function() {
            if( !_active ) {                
                _active = true;
                if( undefined === _previousTime ) {
                    _previousTime = Date.now();
                }
                if( !_running ) {
                    requestAnimationFrame( run );
                }
            }
        };
        
        var run = function() {
            if( _active && !_running ) {
                _running = true;
                
                ++ _frame;
                
                var delta = Date.now() - _previousTime;
                _previousTime += delta;
                _tick( delta );        // Send tick event
                dispatch();            // Dispatch queued tasks
                if( _active ) {
                    requestAnimationFrame( run );
                }
                
                _running = false;
            }            
        };        
        
        var dispatch = function() {
            for( var phase in _phases ) {
                var dag = _phases[phase];
                if( !_schedule ) {
                    _schedule = _phases[phase].sort();
                }

                while( _schedule.length > 0 ) {
                    var task = _tasks[_schedule.shift()];

                    if( task && task.active ) {
                        task.scheduled = false;
                        try{                            
                            task.callback();
                        } catch( e ) {
                            // Suspend the scheduler and return
                            console.log( e );
                            that.suspend();
                            return;
                        }

                        if( task.active ) {
                            task.scheduled = true;<commit_msg>Removed console output from the scheduler.<commit_after>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global define: false, console: false, window: false, setTimeout: false */

define( function ( require ) {
    
    var lang = require( 'lang' );
    var Delegate = require( 'common/delegate' );
    var Task = require( './task' );
    var Timer = require( './timer' );
    var Graph = require( 'common/graph' );
    var phases = require( 'core/scheduler-phases' );
    
    var Scheduler = function( options ) {
        
        options = options || {};
        
        var _tasks = {},
            _phases = {};
        
        for( var phase in phases ) {
            _phases[phases[phase]] = new Graph();
        }
        
        var _running = false,
            that = this,              
            _previousTime,
            _schedule,
            _tick = new Delegate();    // Time signal, sent each frame
        
        this.Timer = Timer({ tick: _tick });        
        this.Task = Task({ manager: this });
        
        Object.defineProperty( this, 'phases', {
           get: function() {
               return phases;
           } 
        });

        var _realTime = new this.Timer();
        Object.defineProperty( this, 'realTime', {
            get: function() {
                return _realTime;
            }
        });
        
        var _simulationTime = new this.Timer();
        Object.defineProperty( this, 'simulationTime', {
            get: function() {
                return _simulationTime;
            }
        });
        
        var _frame = 0;
        Object.defineProperty( this, 'frame', {
            get: function() {
                return _frame;
            }
        });
        
        var _active = false;
        Object.defineProperty( this, 'active', {
            get: function() {
                return _active;
            }
        });
              
        this.suspend = function() {
            _active = false;
        };
        
        this.clear = function() {
            _tasks = {};
        };
        
        this.resume = function() {
            if( !_active ) {                
                _active = true;
                if( undefined === _previousTime ) {
                    _previousTime = Date.now();
                }
                if( !_running ) {
                    requestAnimationFrame( run );
                }
            }
        };
        
        var run = function() {
            if( _active && !_running ) {
                _running = true;
                
                ++ _frame;
                
                var delta = Date.now() - _previousTime;
                _previousTime += delta;
                _tick( delta );        // Send tick event
                dispatch();            // Dispatch queued tasks
                if( _active ) {
                    requestAnimationFrame( run );
                }
                
                _running = false;
            }            
        };        
        
        var dispatch = function() {
            for( var phase in _phases ) {
                var dag = _phases[phase];
                if( !_schedule ) {
                    _schedule = _phases[phase].sort();
                }

                while( _schedule.length > 0 ) {
                    var task = _tasks[_schedule.shift()];

                    if( task && task.active ) {
                        task.scheduled = false;
                        try{                            
                            task.callback();
                        } catch( e ) {
                            // Suspend the scheduler and return
                            that.suspend();
                            return;
                        }

                        if( task.active ) {
                            task.scheduled = true;
{'fraction_non_alphanumeric': 0.10136080376446649, 'fraction_numerical': 0.0005087116876510238, 'mean_word_length': 0.9450902794954242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4294406', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1839, 'n_words': 464}