NotificationFactories.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { CompleteNotification, NextNotification, ErrorNotification } from './types';
  2. /**
  3. * A completion object optimized for memory use and created to be the
  4. * same "shape" as other notifications in v8.
  5. * @internal
  6. */
  7. export const COMPLETE_NOTIFICATION = (() => createNotification('C', undefined, undefined) as CompleteNotification)();
  8. /**
  9. * Internal use only. Creates an optimized error notification that is the same "shape"
  10. * as other notifications.
  11. * @internal
  12. */
  13. export function errorNotification(error: any): ErrorNotification {
  14. return createNotification('E', undefined, error) as any;
  15. }
  16. /**
  17. * Internal use only. Creates an optimized next notification that is the same "shape"
  18. * as other notifications.
  19. * @internal
  20. */
  21. export function nextNotification<T>(value: T) {
  22. return createNotification('N', value, undefined) as NextNotification<T>;
  23. }
  24. /**
  25. * Ensures that all notifications created internally have the same "shape" in v8.
  26. *
  27. * TODO: This is only exported to support a crazy legacy test in `groupBy`.
  28. * @internal
  29. */
  30. export function createNotification(kind: 'N' | 'E' | 'C', value: any, error: any) {
  31. return {
  32. kind,
  33. value,
  34. error,
  35. };
  36. }