Raanan Weber 5 éve
szülő
commit
71cb90c877
1 módosított fájl, 8 hozzáadás és 0 törlés
  1. 8 0
      src/Misc/timer.ts

+ 8 - 0
src/Misc/timer.ts

@@ -33,6 +33,10 @@ export interface ITimerOptions<T> {
      */
     onEnded?: (data: ITimerData<any>) => void;
     /**
+     * Will be triggered when the break condition has met (prematurely ended)
+     */
+    onAborted?: (data: ITimerData<any>) => void;
+    /**
      * Optional function to execute on each tick (or count)
      */
     onTick?: (data: ITimerData<any>) => void;
@@ -105,6 +109,7 @@ export function setAndStartTimer(options: ITimerOptions<any>): Nullable<Observer
         options.onTick && options.onTick(data);
         if (options.breakCondition && options.breakCondition()) {
             options.contextObservable.remove(observer);
+            options.onAborted && options.onAborted(data);
         }
         if (timer >= options.timeout) {
             options.contextObservable.remove(observer);
@@ -165,6 +170,9 @@ export class AdvancedTimer<T = any> implements IDisposable {
         if (options.onTick) {
             this.onEachCountObservable.add(options.onTick);
         }
+        if (options.onAborted) {
+            this.onTimerAbortedObservable.add(options.onAborted);
+        }
     }
 
     /**