Skip to content

Commit

Permalink
feat(interceptors): add dispatchLater()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 27, 2018
1 parent f84fe45 commit f4a095a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/interceptors/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface IDispatch {
readonly state: ReadonlyAtom<any>;
dispatch(event: Event);
dispatchNow(event: Event);
dispatchLater(event: Event, delay?: number);
}

export interface Interceptor {
Expand Down
11 changes: 11 additions & 0 deletions packages/interceptors/src/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ export class StatelessEventBus implements
(this.currQueue || this.eventQueue).push(e);
}

/**
* Dispatches given event after `delay` milliseconds
* (by default 17).
*
* @param e
* @param delay
*/
dispatchLater(e: api.Event, delay = 17) {
setTimeout(() => this.dispatch(e), delay);
}

/**
* Triggers processing of current event queue and returns `true` if
* any events have been processed.
Expand Down

0 comments on commit f4a095a

Please sign in to comment.