Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/task_test_ui.js

Issue 9084006: task.js: cooperative multitasking for long-running tasks (Closed)
Patch Set: Created Dec. 26, 2012, 5:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/content/crawler_ui.js ('k') | lib/counter_task.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/task_test_ui.js
===================================================================
--- a/chrome/content/task_test_ui.js
+++ b/chrome/content/task_test_ui.js
@@ -1,4 +1,84 @@
-function task_test_click()
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+var {Long_Task} = require( "task" );
+var {tg_count} = require( "counter_task" );
+
+var current_task = null;
+
+function update_status( s, perform_log )
{
- Cu.reportError( "Clicked" );
-}
+ var status_field = document.getElementById( "task_status" );
+ if ( status_field.childNodes.length > 0 )
+ {
+ status_field.removeChild( status_field.childNodes[0] );
+ }
+ status_field.appendChild( document.createTextNode( s ) );
+ if ( arguments.length >= 2 && perform_log )
+ {
+ log( s );
+ }
+}
+
+function update_button( b )
+{
+ var button = document.getElementById( "task_go" );
+ if ( b ) {
+ button.label = "Cancel"
+ } else {
+ button.label = "Start"
+ }
+
+}
+
+function task_finished()
+{
+ if ( current_task.cancelled )
+ {
+ var status = "Cancelled";
+ }
+ else
+ {
+ status = "Finished";
+ }
+ update_status( status );
+ update_button( false );
+ current_task = null;
+}
+
+function task_count( n )
+{
+ update_status( "Count " + n, false );
+}
+
+/*
+ * We're overloading the start button also to handle cancellation.
+ */
+function task_start_click()
+{
+ if ( !current_task )
+ {
+ log( "Clicked start" );
+ let count = document.getElementById( "task_count" ).value;
+ let limit = document.getElementById( "task_limit" ).value;
+ current_task = new Long_Task( tg_count( count, task_count, task_finished ), limit );
+ update_status( "Started" );
+ update_button( true );
+ current_task.run();
+ }
+ else
+ {
+ current_task.cancel();
+ update_button( false );
+ // We have a running task, so cancel it.
+ }
+}
+
+
+function log( msg )
+{
+ Cu.reportError( "task_ui: " + msg );
+}
« no previous file with comments | « chrome/content/crawler_ui.js ('k') | lib/counter_task.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld