summaryrefslogtreecommitdiffstats
path: root/apps/files/js/semaphore.js
diff options
context:
space:
mode:
authorTomasz Grobelny <tomasz@grobelny.net>2018-11-14 22:39:12 +0100
committerTomasz Grobelny <tomasz@grobelny.net>2018-11-24 23:55:33 +0100
commit1f6f276fa02533a696fc4157f061a4482be02917 (patch)
treeb80ff821c43e1293cdee4655bd5e6a0b883e4a2a /apps/files/js/semaphore.js
parent7bafa54ae168a25b47d579fdca4cec19f2e1534f (diff)
downloadnextcloud-server-1f6f276fa02533a696fc4157f061a4482be02917.tar.gz
nextcloud-server-1f6f276fa02533a696fc4157f061a4482be02917.zip
Add progress reporting to move and copy operations
Signed-off-by: Tomasz Grobelny <tomasz@grobelny.net>
Diffstat (limited to 'apps/files/js/semaphore.js')
-rw-r--r--apps/files/js/semaphore.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/files/js/semaphore.js b/apps/files/js/semaphore.js
new file mode 100644
index 00000000000..044f0af23f3
--- /dev/null
+++ b/apps/files/js/semaphore.js
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function(){
+ var Semaphore = function(max) {
+ var counter = 0;
+ var waiting = [];
+
+ this.acquire = function() {
+ if(counter < max) {
+ counter++;
+ return new Promise(function(resolve) { resolve(); });
+ } else {
+ return new Promise(function(resolve) { waiting.push(resolve); });
+ }
+ };
+
+ this.release = function() {
+ counter--;
+ if (waiting.length > 0 && counter < max) {
+ counter++;
+ var promise = waiting.shift();
+ promise();
+ }
+ };
+ };
+
+ OCA.Files.Semaphore = Semaphore;
+
+})();