| 1 |
import { EmptyError } from './util/EmptyError'; |
| 2 |
export function lastValueFrom(source, config) { |
| 3 |
const hasConfig = typeof config === 'object'; |
| 4 |
return new Promise((resolve, reject) => { |
| 5 |
let _hasValue = false; |
| 6 |
let _value; |
| 7 |
source.subscribe({ |
| 8 |
next: (value) => { |
| 9 |
_value = value; |
| 10 |
_hasValue = true; |
| 11 |
}, |
| 12 |
error: reject, |
| 13 |
complete: () => { |
| 14 |
if (_hasValue) { |
| 15 |
resolve(_value); |
| 16 |
} |
| 17 |
else if (hasConfig) { |
| 18 |
resolve(config.defaultValue); |
| 19 |
} |
| 20 |
else { |
| 21 |
reject(new EmptyError()); |
| 22 |
} |
| 23 |
}, |
| 24 |
}); |
| 25 |
}); |
| 26 |
} |
| 27 |
//# sourceMappingURL=lastValueFrom.js.map |