Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. export abstract class BlockingAction {
  2. type: string;
  3. abstract setup(iter: IterableIterator<BlockingAction>): void;
  4. handleNext(iter: IterableIterator<BlockingAction>): void {
  5. let n = iter.next();
  6. if(n.done)
  7. return;
  8.  
  9. n.value.setup(iter);
  10. };
  11.  
  12. public static startCoroutine(func: () => IterableIterator<BlockingAction>): void {
  13. let iter = func();
  14. let n = iter.next();
  15. if(n.done)
  16. return;
  17.  
  18. n.value.setup(iter);
  19. }
  20. }
  21.  
  22. export class Wait extends BlockingAction {
  23. wait: number;
  24.  
  25. constructor(timeout : number) {
  26. super();
  27. this.wait = timeout;
  28. }
  29.  
  30. setup(iter: IterableIterator<BlockingAction>) : void {
  31. let t = this;
  32. setTimeout(function(){
  33. t.handleNext(iter);
  34. }, this.wait);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement