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

Unified Diff: lib/action_platform.js

Issue 10233013: Crawler, second version (Closed)
Patch Set: Created April 12, 2013, 1:38 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 | « lib/action.js ('k') | lib/application.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/action_platform.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/action_platform.js
@@ -0,0 +1,77 @@
+/**
+ * @fileOverview A platform-specific primitive set for the module action.js. This version is for Firefox extensions.
+ */
+
+/**
+ * @namespace
+ */
+Action_Platform = {};
+
+/**
+ * An instance of the NS thread manager.
+ * @type {nsIThreadManager}
+ */
+Action_Platform.thread_manager = Cc["@mozilla.org/thread-manager;1"].createInstance( Ci.nsIThreadManager );
+
+/**
+ * Dispatch a function into the next JavaScript thread.
+ * @param {function} f
+ */
+Action_Platform.dispatch = function( f )
+{
+ Action_Platform.thread_manager.currentThread.dispatch(
+ {run: f},
+ Ci.nsIEventTarget.DISPATCH_NORMAL
+ );
+};
+
+/**
+ * Timer class for the NS timer.
+ * @constructor
+ */
+Action_Platform.Timer = function()
+{
+ /**
+ * An instance of the NS timer, which
+ * @type {*}
+ */
+ this.timer = Cc["@mozilla.org/timer;1"].createInstance( Ci.nsITimer )
+};
+
+/**
+ * @param {function} f
+ * @param {number} duration
+ */
+Action_Platform.Timer.prototype.set = function( f, duration )
+{
+ this.timer.initWithCallback( f, duration, Ci.nsITimer.TYPE_ONE_SHOT )
+};
+
+Action_Platform.Timer.prototype.clear = function()
+{
+ this.timer.cancel();
+};
+
+/**
+ * Set the timer.
+ * @param {function} f
+ * @param {number} duration
+ * @return {Action_Platform.Timer}
+ */
+Action_Platform.set_timer = function( f, duration )
+{
+ var t = new Action_Platform.Timer();
+ t.set( f, duration );
+ return t;
+};
+
+/**
+ * Clear the timer.
+ * @param {Action_Platform.Timer} id
+ */
+Action_Platform.clear_timer = function( id )
+{
+ id.clear();
+};
+
+exports.Action_Platform = Action_Platform;
« no previous file with comments | « lib/action.js ('k') | lib/application.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld