Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. interface GenericAsyncCallback<E, T> {
  2. (err: E | null, ...results: T[]): void
  3. }
  4.  
  5. const asyncApi = (callback: GenericAsyncCallback<Error, number>) => {
  6. setTimeout(() => {
  7. const error = Math.random() > 0.5 ? new Error(`Connection Timeout`) : null;
  8.  
  9. if (error) callback(error);
  10. else callback(null, Date.now());
  11. }, 1000);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement