From ca353d082901c692ae13dee1eade77ac4ed685ec Mon Sep 17 00:00:00 2001
From: Spencer Ahrens <sahrens@fb.com>
Date: Thu, 24 Mar 2016 19:43:42 -0700
Subject: [PATCH] A little more debugging code for Incremental

Reviewed By: astreet

Differential Revision: D3091688

fb-gh-sync-id: 4f91d5126a16b56904fa4af7acdc32b9bb873c6d
shipit-source-id: 4f91d5126a16b56904fa4af7acdc32b9bb873c6d
---
 Libraries/Experimental/Incremental.js       |  1 +
 Libraries/Interaction/InteractionManager.js |  4 +++-
 Libraries/Interaction/TaskQueue.js          | 11 ++++++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Libraries/Experimental/Incremental.js b/Libraries/Experimental/Incremental.js
index 086215fd9..052506cc2 100644
--- a/Libraries/Experimental/Incremental.js
+++ b/Libraries/Experimental/Incremental.js
@@ -129,6 +129,7 @@ class Incremental extends React.Component {
         this.setState({doIncrementalRender: true}, resolve);
       }),
     }).then(() => {
+      DEBUG && console.log('call onDone for ' + this.getName());
       this._mounted && this.props.onDone && this.props.onDone();
     });
   }
diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js
index 9d0547251..9a2922629 100644
--- a/Libraries/Interaction/InteractionManager.js
+++ b/Libraries/Interaction/InteractionManager.js
@@ -25,6 +25,8 @@ import type {Task} from 'TaskQueue';
 
 const _emitter = new EventEmitter();
 
+const DEBUG_DELAY = 0;
+
 /**
  * InteractionManager allows long-running work to be scheduled after any
  * interactions/animations have completed. In particular, this allows JavaScript
@@ -143,7 +145,7 @@ let _deadline = -1;
 function _scheduleUpdate() {
   if (!_nextUpdateHandle) {
     if (_deadline > 0) {
-      _nextUpdateHandle = setTimeout(_processUpdate, 0);
+      _nextUpdateHandle = setTimeout(_processUpdate, 0 + DEBUG_DELAY);
     } else {
       _nextUpdateHandle = setImmediate(_processUpdate);
     }
diff --git a/Libraries/Interaction/TaskQueue.js b/Libraries/Interaction/TaskQueue.js
index f623f7a3a..211540b16 100644
--- a/Libraries/Interaction/TaskQueue.js
+++ b/Libraries/Interaction/TaskQueue.js
@@ -25,6 +25,8 @@ type PromiseTask = {
 };
 export type Task = Function | SimpleTask | PromiseTask;
 
+const DEBUG = false;
+
 /**
  * TaskQueue - A system for queueing and executing a mix of simple callbacks and
  * trees of dependent tasks based on Promises. No tasks are executed unless
@@ -81,13 +83,15 @@ class TaskQueue {
    * Executes the next task in the queue.
    */
   processNext(): void {
-    let queue = this._getCurrentQueue();
+    const queue = this._getCurrentQueue();
     if (queue.length) {
       const task = queue.shift();
       try {
         if (task.gen) {
+          DEBUG && console.log('genPromise for task ' + task.name);
           this._genPromise((task: any)); // Rather than annoying tagged union
         } else if (task.run) {
+          DEBUG && console.log('run task ' + task.name);
           task.run();
         } else {
           invariant(
@@ -95,6 +99,7 @@ class TaskQueue {
             'Expected Function, SimpleTask, or PromiseTask, but got: ' +
               JSON.stringify(task)
           );
+          DEBUG && console.log('run anonymous task');
           task();
         }
       } catch (e) {
@@ -115,6 +120,7 @@ class TaskQueue {
         queue.tasks.length === 0 &&
         this._queueStack.length > 1) {
       this._queueStack.pop();
+      DEBUG && console.log('popped queue: ', {stackIdx, queueStackSize: this._queueStack.length});
       return this._getCurrentQueue();
     } else {
       return queue.tasks;
@@ -128,8 +134,11 @@ class TaskQueue {
     // happens once it is fully processed.
     this._queueStack.push({tasks: [], popable: false});
     const stackIdx = this._queueStack.length - 1;
+    DEBUG && console.log('push new queue: ', {stackIdx});
+    DEBUG && console.log('exec gen task ' + task.name);
     ErrorUtils.applyWithGuard(task.gen)
       .then(() => {
+        DEBUG && console.log('onThen for gen task ' + task.name, {stackIdx, queueStackSize: this._queueStack.length});
         this._queueStack[stackIdx].popable = true;
         this.hasTasksToProcess() && this._onMoreTasks();
       })