variableQueryObserver.ts 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Observer, Subscription } from 'rxjs';
  2. import { LoadingState } from '@grafana/data';
  3. import { UpdateOptionsResults } from './VariableQueryRunner';
  4. export function variableQueryObserver(
  5. resolve: (value?: any) => void,
  6. reject: (value?: any) => void,
  7. subscription: Subscription
  8. ): Observer<UpdateOptionsResults> {
  9. const observer: Observer<UpdateOptionsResults> = {
  10. next: (results) => {
  11. if (results.state === LoadingState.Error) {
  12. subscription.unsubscribe();
  13. reject(results.error);
  14. return;
  15. }
  16. if (results.state === LoadingState.Done) {
  17. subscription.unsubscribe();
  18. resolve();
  19. return;
  20. }
  21. },
  22. error: (err) => {
  23. subscription.unsubscribe();
  24. reject(err);
  25. },
  26. complete: () => {
  27. subscription.unsubscribe();
  28. resolve();
  29. },
  30. };
  31. return observer;
  32. }