diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2016-09-19 12:04:21 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-09-19 13:17:54 -0700 |
commit | 9fc431a618e0b09e3815ed86d014d65d56bfb6ba (patch) | |
tree | e0da88e105982ed47f09465232df78270aa55310 | |
parent | 2f53824587dc10efc8f4ad130d985519126f10c1 (diff) |
Made the promise returned by fetchAndParseMetadata resolve only after parsing finishes, not at some point after parsing begins. This makes the relevant message disappear only after parsing completes.
Change: 133621202
-rw-r--r-- | tensorflow/tensorboard/components/tf-graph-common/lib/parser.ts | 8 | ||||
-rw-r--r-- | tensorflow/tensorboard/components/tf-graph-common/lib/util.ts | 40 |
2 files changed, 45 insertions, 3 deletions
diff --git a/tensorflow/tensorboard/components/tf-graph-common/lib/parser.ts b/tensorflow/tensorboard/components/tf-graph-common/lib/parser.ts index b245009a04..8608a1a0ad 100644 --- a/tensorflow/tensorboard/components/tf-graph-common/lib/parser.ts +++ b/tensorflow/tensorboard/components/tf-graph-common/lib/parser.ts @@ -65,9 +65,11 @@ export function fetchAndParseMetadata(path: string, tracker: ProgressTracker) { }, tracker) .then((arrayBuffer: ArrayBuffer) => { - return tf.graph.util.runTask('Parsing metadata.pbtxt', 60, () => { - return arrayBuffer != null ? parseStatsPbTxt(arrayBuffer) : null; - }, tracker); + return tf.graph.util.runAsyncPromiseTask( + 'Parsing metadata.pbtxt', 60, () => { + return arrayBuffer != null ? parseStatsPbTxt(arrayBuffer) : + Promise.resolve(null); + }, tracker); }); } diff --git a/tensorflow/tensorboard/components/tf-graph-common/lib/util.ts b/tensorflow/tensorboard/components/tf-graph-common/lib/util.ts index f41fd3c591..8a8a29ca08 100644 --- a/tensorflow/tensorboard/components/tf-graph-common/lib/util.ts +++ b/tensorflow/tensorboard/components/tf-graph-common/lib/util.ts @@ -145,6 +145,46 @@ module tf.graph.util { } /** + * Asynchronously runs an expensive task that returns a promise. Updates the + * tracker's progress after the promise resolves. Returns a new promise that + * resolves after the progress is updated. + */ + export function runAsyncPromiseTask<T>( + msg: string, incProgressValue: number, task: () => Promise<T>, + tracker: ProgressTracker): Promise<T> { + return new Promise((resolve, reject) => { + let handleError = function(e) { + // Errors that happen inside asynchronous tasks are + // reported to the tracker using a user-friendly message. + tracker.reportError('Failed ' + msg, e); + reject(e); + }; + + // Update the progress message to say the current running task. + tracker.setMessage(msg); + // Run the expensive task with a delay that gives enough time for the + // UI to update. + setTimeout(function() { + try { + let start = Date.now(); + task() + .then(function(value) { + /* tslint:disable */ + console.log(msg, ':', Date.now() - start, 'ms'); + // Update the progress value. + tracker.updateProgress(incProgressValue); + // Return the result to be used by other tasks. + resolve(value); + }) + .catch(handleError); + } catch (e) { + handleError(e); + } + }, ASYNC_TASK_DELAY); + }); + } + + /** * Returns a query selector with escaped special characters that are not * allowed in a query selector. */ |