()
| 3011 | |
| 3012 | getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { |
| 3013 | function DelayedFunctionScheduler() { |
| 3014 | this.scheduledLookup_ = [] |
| 3015 | this.scheduledFunctions_ = {} |
| 3016 | this.currentTime_ = 0 |
| 3017 | this.delayedFnCount_ = 0 |
| 3018 | this.deletedKeys_ = [] |
| 3019 | |
| 3020 | this.tick = function(millis, tickDate) { |
| 3021 | millis = millis || 0 |
| 3022 | const endTime = this.currentTime_ + millis |
| 3023 | |
| 3024 | this.runScheduledFunctions_(endTime, tickDate) |
| 3025 | } |
| 3026 | |
| 3027 | this.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { |
| 3028 | let f |
| 3029 | if (typeof funcToCall === "string") { |
| 3030 | f = function() { |
| 3031 | // eslint-disable-next-line no-eval |
| 3032 | return eval(funcToCall) |
| 3033 | } |
| 3034 | } else { |
| 3035 | f = funcToCall |
| 3036 | } |
| 3037 | |
| 3038 | millis = millis || 0 |
| 3039 | timeoutKey = timeoutKey || ++this.delayedFnCount_ |
| 3040 | runAtMillis = runAtMillis || this.currentTime_ + millis |
| 3041 | |
| 3042 | const funcToSchedule = { |
| 3043 | runAtMillis: runAtMillis, |
| 3044 | funcToCall: f, |
| 3045 | recurring: recurring, |
| 3046 | params: params, |
| 3047 | timeoutKey: timeoutKey, |
| 3048 | millis: millis, |
| 3049 | } |
| 3050 | |
| 3051 | if (runAtMillis in this.scheduledFunctions_) { |
| 3052 | this.scheduledFunctions_[runAtMillis].push(funcToSchedule) |
| 3053 | } else { |
| 3054 | this.scheduledFunctions_[runAtMillis] = [funcToSchedule] |
| 3055 | this.scheduledLookup_.push(runAtMillis) |
| 3056 | this.scheduledLookup_.sort(function(a, b) { |
| 3057 | return a - b |
| 3058 | }) |
| 3059 | } |
| 3060 | |
| 3061 | return timeoutKey |
| 3062 | } |
| 3063 | |
| 3064 | this.removeFunctionWithId = function(timeoutKey) { |
| 3065 | this.deletedKeys_.push(timeoutKey) |
| 3066 | |
| 3067 | for (const runAtMillis in this.scheduledFunctions_) { |
| 3068 | const funcs = this.scheduledFunctions_[runAtMillis] |
| 3069 | const i = indexOfFirstToPass(funcs, function(func) { |
| 3070 | return func.timeoutKey === timeoutKey |
nothing calls this directly
no test coverage detected