* @param {string} file * @param {number} timeout * @private * @returns {Promise }
(file, timeout)
| 221 | * @returns {Promise<any>} |
| 222 | */ |
| 223 | function isFileExists(file, timeout) { |
| 224 | return new Promise((resolve, reject) => { |
| 225 | const timer = setTimeout(() => { |
| 226 | watcher.close() |
| 227 | reject(new Error('File did not exists and was not created during the timeout.')) |
| 228 | }, timeout) |
| 229 | |
| 230 | const dir = path.dirname(file) |
| 231 | const basename = path.basename(file) |
| 232 | const watcher = fs.watch(dir, (eventType, filename) => { |
| 233 | if (eventType === 'rename' && filename === basename) { |
| 234 | clearTimeout(timer) |
| 235 | watcher.close() |
| 236 | resolve() |
| 237 | } |
| 238 | }) |
| 239 | |
| 240 | fs.access(file, fs.constants.R_OK, err => { |
| 241 | if (!err) { |
| 242 | clearTimeout(timer) |
| 243 | watcher.close() |
| 244 | resolve() |
| 245 | } |
| 246 | }) |
| 247 | }) |
| 248 | } |