firstValueFrom.js 784 B

123456789101112131415161718192021222324
  1. import { EmptyError } from './util/EmptyError';
  2. import { SafeSubscriber } from './Subscriber';
  3. export function firstValueFrom(source, config) {
  4. var hasConfig = typeof config === 'object';
  5. return new Promise(function (resolve, reject) {
  6. var subscriber = new SafeSubscriber({
  7. next: function (value) {
  8. resolve(value);
  9. subscriber.unsubscribe();
  10. },
  11. error: reject,
  12. complete: function () {
  13. if (hasConfig) {
  14. resolve(config.defaultValue);
  15. }
  16. else {
  17. reject(new EmptyError());
  18. }
  19. },
  20. });
  21. source.subscribe(subscriber);
  22. });
  23. }
  24. //# sourceMappingURL=firstValueFrom.js.map