[gnome-shell/wip/gdm-shell] wip: make Hold objects tasks too (needs squash)
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gdm-shell] wip: make Hold objects tasks too (needs squash)
- Date: Fri, 1 Jul 2011 20:02:47 +0000 (UTC)
commit c543a17b4ab9ed95d410d0c9424faa68af1d64b5
Author: Ray Strode <rstrode redhat com>
Date: Fri Jul 1 16:00:34 2011 -0400
wip: make Hold objects tasks too (needs squash)
This way hold objects can just get added to a batch directly
to hold it up.
js/misc/batch.js | 79 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 49 insertions(+), 30 deletions(-)
---
diff --git a/js/misc/batch.js b/js/misc/batch.js
index 06a4b67..ce4a08a 100644
--- a/js/misc/batch.js
+++ b/js/misc/batch.js
@@ -21,45 +21,68 @@
const Lang = imports.lang;
const Signals = imports.signals;
+function Task(task) {
+ this._init(task);
+}
+
+Task.prototype = {
+ _init: function(handler) {
+ this._handler = handler;
+ },
+
+ run: function() {
+ if (this._handler)
+ return this._handler();
+ },
+};
+Signals.addSignalMethods(Task.prototype);
+
function Hold() {
this._init();
}
Hold.prototype = {
+ __proto__: Task.prototype,
+
_init: function() {
+ Task.prototype._init.call(this,
+ Lang.bind(this, function () {
+ return this;
+ }));
+
this._acquisitions = 1;
},
acquire: function() {
+ if (this._acquisitions <= 0)
+ throw new Error("Cannot acquire hold after its been released");
this._acquisitions++;
},
+ acquireUntilAfter: function(hold) {
+ if (!hold.isAcquired())
+ return;
+
+ this.acquire();
+ let signalId = hold.connect('release', Lang.bind(this, function() {
+ hold.disconnect(signalId);
+ this.release();
+ }));
+ },
+
release: function() {
this._acquisitions--;
- if (this._acquisitions == 0) {
+ if (this._acquisitions == 0)
this.emit('release');
- }
+ },
+
+ isAcquired: function() {
+ return this._acquisitions > 0;
}
}
Signals.addSignalMethods(Hold.prototype);
-function Task(task) {
- this._init(task);
-}
-
-Task.prototype = {
- _init: function(handler) {
- this._handler = handler;
- },
-
- run: function() {
- if (this._handler)
- return this._handler();
- },
-};
-Signals.addSignalMethods(Task.prototype);
-
function Batch(tasks) {
this._init(tasks);
}
@@ -79,7 +102,7 @@ Batch.prototype = {
} else if (typeof tasks[i] == 'function') {
task = new Task(tasks[i]);
} else {
- throw new Error('Batch tasks must be functions or Task or Batch objects');
+ throw new Error('Batch tasks must be functions or Task, Hold or Batch objects');
}
this.tasks.push(task);
@@ -149,12 +172,7 @@ ConcurrentBatch.prototype = {
let hold = this.runTask();
if (hold) {
- this.hold.acquire();
- hold.connect('release',
- Lang.bind(this, function() {
- this.hold.release();
- this.nextTask();
- }));
+ this.hold.acquireUntilAfter(hold);
}
// Regardless of the state of the just run task,
@@ -179,13 +197,14 @@ ConsecutiveBatch.prototype = {
process: function() {
let hold = this.runTask();
- if (hold) {
+ if (hold && hold.isAcquired()) {
// This task is inhibiting the batch. Wait on it
// before processing the next one.
- hold.connect('release',
- Lang.bind(this, function() {
- this.nextTask();
- }));
+ let signalId = hold.connect('release',
+ Lang.bind(this, function() {
+ hold.disconnect(signalId);
+ this.nextTask();
+ }));
return;
} else {
// This task finished, process the next one
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]