firstValueFrom.js 770 B

123456789101112131415161718192021222324
  1. import { EmptyError } from './util/EmptyError';
  2. import { SafeSubscriber } from './Subscriber';
  3. export function firstValueFrom(source, config) {
  4. const hasConfig = typeof config === 'object';
  5. return new Promise((resolve, reject) => {
  6. const subscriber = new SafeSubscriber({
  7. next: (value) => {
  8. resolve(value);
  9. subscriber.unsubscribe();
  10. },
  11. error: reject,
  12. complete: () => {
  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