소스 검색

custom scheduling callback for PriorityQueue

Bruno Fanini 3 년 전
부모
커밋
370c2b0ae6
1개의 변경된 파일10개의 추가작업 그리고 11개의 파일을 삭제
  1. 10 11
      src/utilities/PriorityQueue.js

+ 10 - 11
src/utilities/PriorityQueue.js

@@ -12,11 +12,18 @@ class PriorityQueue {
 		this.autoUpdate = true;
 
 		this.priorityCallback = () => {
-
 			throw new Error( 'PriorityQueue: PriorityCallback function not defined.' );
+		};
 
+		// Customizable scheduling callback. Default using requestAnimationFrame()
+		this.schedulingCallback = func => {
+			requestAnimationFrame( func );
 		};
 
+		this._runjobs = ()=>{
+			this.tryRunJobs();
+			this.scheduled = false;
+		};
 	}
 
 	sort() {
@@ -107,19 +114,11 @@ class PriorityQueue {
 	}
 
 	scheduleJobRun() {
+		if ( !this.scheduled ){
+			this.schedulingCallback( this._runjobs );
 
-		if ( ! this.scheduled ) {
-
-			requestAnimationFrame( () => {
-
-				this.tryRunJobs();
-				this.scheduled = false;
-
-			} );
 			this.scheduled = true;
-
 		}
-
 	}
 
 }