Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Type definitions for retry 0.12
  2. // Project: https://github.com/tim-kos/node-retry
  3. // Definitions by: Stan Goldmann <https://github.com/krenor>
  4. // BendingBender <https://github.com/BendingBender>
  5. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  6. // TypeScript Version: 2.3
  7. export interface RetryOperation {
  8. /**
  9. * Returns an array of all errors that have been passed to `retryOperation.retry()` so far.
  10. * The returning array has the errors ordered chronologically based on when they were passed to
  11. * `retryOperation.retry()`, which means the first passed error is at index zero and the last is at the last index.
  12. */
  13. errors(): Error[];
  14. /**
  15. * A reference to the error object that occured most frequently.
  16. * Errors are compared using the `error.message` property.
  17. * If multiple error messages occured the same amount of time, the last error object with that message is returned.
  18. *
  19. * @return If no errors occured so far the value will be `null`.
  20. */
  21. mainError(): Error | null;
  22. /**
  23. * Defines the function that is to be retried and executes it for the first time right away.
  24. *
  25. * @param fn The function that is to be retried. `currentAttempt` represents the number of attempts
  26. * callback has been executed so far.
  27. * @param [timeoutOps.timeout] A timeout in milliseconds.
  28. * @param [timeoutOps.callback] Callback to execute when the operation takes longer than the timeout.
  29. */
  30. attempt(fn: (currentAttempt: number) => void, timeoutOps?: AttemptTimeoutOptions): void;
  31. /**
  32. * Returns `false` when no `error` value is given, or the maximum amount of retries has been reached.
  33. * Otherwise it returns `true`, and retries the operation after the timeout for the current attempt number.
  34. */
  35. retry(err?: Error): boolean;
  36. /**
  37. * Stops the operation being retried. Useful for aborting the operation on a fatal error etc.
  38. */
  39. stop(): void;
  40. /**
  41. * Resets the internal state of the operation object, so that you can call `attempt()` again as if
  42. * this was a new operation object.
  43. */
  44. reset(): void;
  45. /**
  46. * Returns an int representing the number of attempts it took to call `fn` before it was successful.
  47. */
  48. attempts(): number;
  49. }
  50. export interface AttemptTimeoutOptions {
  51. /**
  52. * A timeout in milliseconds.
  53. */
  54. timeout?: number | undefined;
  55. /**
  56. * Callback to execute when the operation takes longer than the timeout.
  57. */
  58. callback?(): void;
  59. }
  60. /**
  61. * Create a new RetryOperation object.
  62. *
  63. * @param [options.retries=10] The maximum amount of times to retry the operation.
  64. * @param [options.factor=2] The exponential factor to use.
  65. * @param [options.minTimeout=1000] The number of milliseconds before starting the first retry.
  66. * @param [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
  67. * @param [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
  68. * @param [options.forever=false] Wether to retry forever.
  69. * @param [options.unref=false] Wether to unref the setTimeout's.
  70. *
  71. */
  72. export function operation(options?: OperationOptions): RetryOperation;
  73. export interface OperationOptions extends TimeoutsOptions {
  74. /**
  75. * Whether to retry forever.
  76. * @default false
  77. */
  78. forever?: boolean | undefined;
  79. /**
  80. * Whether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's.
  81. * @default false
  82. */
  83. unref?: boolean | undefined;
  84. /**
  85. * The maximum time (in milliseconds) that the retried operation is allowed to run.
  86. * @default Infinity
  87. */
  88. maxRetryTime?: number | undefined;
  89. }
  90. /** Get an array with timeouts and their return values in milliseconds. */
  91. export function timeouts(options?: TimeoutsOptions): number[];
  92. export interface TimeoutsOptions extends CreateTimeoutOptions {
  93. /**
  94. * The maximum amount of times to retry the operation.
  95. * @default 10
  96. */
  97. retries?: number | undefined;
  98. }
  99. /**
  100. * Create a new timeout (in milliseconds) based on the given parameters.
  101. *
  102. * @param attempt Representing for which retry the timeout should be calculated.
  103. * @return timeout
  104. */
  105. export function createTimeout(attempt: number, options?: CreateTimeoutOptions): number;
  106. export interface CreateTimeoutOptions {
  107. /**
  108. * The exponential factor to use.
  109. * @default 2
  110. */
  111. factor?: number | undefined;
  112. /**
  113. * The number of milliseconds before starting the first retry.
  114. * @default 1000
  115. */
  116. minTimeout?: number | undefined;
  117. /**
  118. * The maximum number of milliseconds between two retries.
  119. * @default Infinity
  120. */
  121. maxTimeout?: number | undefined;
  122. /**
  123. * Randomizes the timeouts by multiplying a factor between 1-2.
  124. * @default false
  125. */
  126. randomize?: boolean | undefined;
  127. }
  128. /**
  129. * Wrap all functions of the object with retry.
  130. *
  131. * @param object The object to be wrapped
  132. * @param methods Methods which need to be wrapped
  133. *
  134. */
  135. export function wrap(object: object, methods?: string[]): void;
  136. export function wrap(object: object, options?: OperationOptions, methods?: string[]): void;