|
1 |
| -var when = require("when"), |
2 |
| - nodefn = require("when/node"), |
3 |
| - model = require("./model"); |
| 1 | +var when = require("when"), |
| 2 | + nodefn = require("when/node"), |
| 3 | + semaphore = require("semaphore"), |
| 4 | + model = require("./model"); |
4 | 5 |
|
5 | 6 | if (typeof(require) !== 'undefined') {
|
6 | 7 | var fs = require("graceful-fs");
|
@@ -42,24 +43,29 @@ Deploy.prototype = {
|
42 | 43 | progress && progress("start", {total: files.length});
|
43 | 44 |
|
44 | 45 | var self = this;
|
| 46 | + var sem = semaphore(20); |
45 | 47 | var results = files.map(function(file) {
|
46 |
| - return nodefn.call(fs.readFile, file.abs).then(function(data) { |
47 |
| - var filePath = file.rel.split("/").map(function(segment) { |
48 |
| - return encodeURIComponent(segment); |
49 |
| - }).join("/"); |
| 48 | + sem.take(function() { |
| 49 | + return nodefn.call(fs.readFile, file.abs).then(function(data) { |
| 50 | + var filePath = file.rel.split("/").map(function(segment) { |
| 51 | + return encodeURIComponent(segment); |
| 52 | + }).join("/"); |
50 | 53 |
|
51 |
| - return self.client.request({ |
52 |
| - url: "/deploys/" + self.id + "/files/" + filePath, |
53 |
| - type: "put", |
54 |
| - body: data, |
55 |
| - contentType: "application/octet-stream", |
56 |
| - ignoreResponse: true |
57 |
| - }).then(function(response) { |
58 |
| - progress && progress("upload", {file: file, total: files.length}); |
59 |
| - return file; |
60 |
| - }).catch(function(response) { |
61 |
| - progress && progress("uploadError", {file:file, message: response.data}); |
62 |
| - return when.reject(response.data); |
| 54 | + return self.client.request({ |
| 55 | + url: "/deploys/" + self.id + "/files/" + filePath, |
| 56 | + type: "put", |
| 57 | + body: data, |
| 58 | + contentType: "application/octet-stream", |
| 59 | + ignoreResponse: true |
| 60 | + }).then(function(response) { |
| 61 | + progress && progress("upload", {file: file, total: files.length}); |
| 62 | + sem.leave(); |
| 63 | + return file; |
| 64 | + }).catch(function(response) { |
| 65 | + progress && progress("uploadError", {file:file, message: response.data}); |
| 66 | + sem.leave(); |
| 67 | + return when.reject(response.data); |
| 68 | + }); |
63 | 69 | });
|
64 | 70 | });
|
65 | 71 | });
|
|
0 commit comments