|
| 1 | +const { |
| 2 | + waitForBucketExists: bucketExists, |
| 3 | + waitForBucketNotExists: bucketNotExists, |
| 4 | +} = require("../../clients/client-s3"); |
| 5 | + |
1 | 6 | module.exports = {
|
2 | 7 | assert: require("./assertions").assert,
|
3 | 8 |
|
@@ -189,55 +194,25 @@ module.exports = {
|
189 | 194 | return buffer;
|
190 | 195 | },
|
191 | 196 |
|
192 |
| - /** |
193 |
| - * Waits for the bucketExists state by periodically calling the underlying S3.headBucket() operation |
194 |
| - * every 5 seconds (at most 20 times). |
195 |
| - */ |
196 | 197 | waitForBucketExists: function (s3client, params, callback) {
|
197 |
| - const maxAttempts = 20; |
198 |
| - let currentAttempt = 0; |
199 |
| - const delay = 5000; |
200 |
| - |
201 |
| - const checkForBucketExists = () => { |
202 |
| - currentAttempt++; |
203 |
| - s3client.headBucket(params, function (err, data) { |
204 |
| - if (currentAttempt > maxAttempts) { |
205 |
| - callback(new Error("waitForBucketExists: max attempts exceeded")); |
206 |
| - } else if (data) { |
207 |
| - callback(); |
208 |
| - } else { |
209 |
| - setTimeout(function () { |
210 |
| - checkForBucketExists(); |
211 |
| - }, delay); |
212 |
| - } |
213 |
| - }); |
214 |
| - }; |
215 |
| - checkForBucketExists(); |
| 198 | + bucketExists({ client: s3client }, params).then( |
| 199 | + function (data) { |
| 200 | + callback(); |
| 201 | + }, |
| 202 | + function (err) { |
| 203 | + callback(err); |
| 204 | + } |
| 205 | + ); |
216 | 206 | },
|
217 | 207 |
|
218 |
| - /** |
219 |
| - * Waits for the bucketNotExists state by periodically calling the underlying S3.headBucket() operation |
220 |
| - * every 5 seconds (at most 20 times). |
221 |
| - */ |
222 | 208 | waitForBucketNotExists: function (s3client, params, callback) {
|
223 |
| - const maxAttempts = 20; |
224 |
| - let currentAttempt = 0; |
225 |
| - const delay = 5000; |
226 |
| - |
227 |
| - const checkForBucketNotExists = () => { |
228 |
| - currentAttempt++; |
229 |
| - s3client.headBucket(params, function (err, data) { |
230 |
| - if (currentAttempt > maxAttempts) { |
231 |
| - callback(new Error("waitForBucketNotExists: max attempts exceeded")); |
232 |
| - } else if (err && err.name === "NotFound") { |
233 |
| - callback(); |
234 |
| - } else { |
235 |
| - setTimeout(function () { |
236 |
| - checkForBucketNotExists(); |
237 |
| - }, delay); |
238 |
| - } |
239 |
| - }); |
240 |
| - }; |
241 |
| - checkForBucketNotExists(); |
| 209 | + bucketNotExists({ client: s3client }, params).then( |
| 210 | + function (data) { |
| 211 | + callback(); |
| 212 | + }, |
| 213 | + function (err) { |
| 214 | + callback(err); |
| 215 | + } |
| 216 | + ); |
242 | 217 | },
|
243 | 218 | };
|
0 commit comments