Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

async.js 1.0KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const stream_1 = require("../readers/stream");
  4. const provider_1 = require("./provider");
  5. class ProviderAsync extends provider_1.default {
  6. constructor() {
  7. super(...arguments);
  8. this._reader = new stream_1.default(this._settings);
  9. }
  10. read(task) {
  11. const root = this._getRootDirectory(task);
  12. const options = this._getReaderOptions(task);
  13. const entries = [];
  14. return new Promise((resolve, reject) => {
  15. const stream = this.api(root, task, options);
  16. stream.once('error', reject);
  17. stream.on('data', (entry) => entries.push(options.transform(entry)));
  18. stream.once('end', () => resolve(entries));
  19. });
  20. }
  21. api(root, task, options) {
  22. if (task.dynamic) {
  23. return this._reader.dynamic(root, options);
  24. }
  25. return this._reader.static(task.patterns, options);
  26. }
  27. }
  28. exports.default = ProviderAsync;