{"action":"opened","issue":{"url":"https://api.github.com/repos/cujojs/most/issues/343","repository_url":"https://api.github.com/repos/cujojs/most","labels_url":"https://api.github.com/repos/cujojs/most/issues/343/labels{/name}","comments_url":"https://api.github.com/repos/cujojs/most/issues/343/comments","events_url":"https://api.github.com/repos/cujojs/most/issues/343/events","html_url":"https://github.com/cujojs/most/issues/343","id":183262092,"number":343,"title":"Support for Virtual Time Scheduling","user":{"login":"tusharmath","id":194482,"avatar_url":"https://avatars.githubusercontent.com/u/194482?v=3","gravatar_id":"","url":"https://api.github.com/users/tusharmath","html_url":"https://github.com/tusharmath","followers_url":"https://api.github.com/users/tusharmath/followers","following_url":"https://api.github.com/users/tusharmath/following{/other_user}","gists_url":"https://api.github.com/users/tusharmath/gists{/gist_id}","starred_url":"https://api.github.com/users/tusharmath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tusharmath/subscriptions","organizations_url":"https://api.github.com/users/tusharmath/orgs","repos_url":"https://api.github.com/users/tusharmath/repos","events_url":"https://api.github.com/users/tusharmath/events{/privacy}","received_events_url":"https://api.github.com/users/tusharmath/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-16T11:28:05Z","updated_at":"2016-10-16T11:28:05Z","closed_at":null,"body":"RxJS has a wonderful abstraction when it comes to scheduling using TimeSchedulers. The major advantage of it is that we can control how time flows across the system without it having any relation with the actual CPU time. This is particularly useful for unit testing where u don't want to wait unnecessarily for the real time to elapse before you can assert your output.\r\n\r\nSo here is my proposal —\r\n\r\nWe pass a `Scheduler` object as the second param to the `Observable`'s  `subscribe` function. \r\n\r\n**Observable**\r\n```ts\r\nexport interface Observable<T> {\r\n  subscribe(observer: Observer<T>, scheduler: Scheduler): Subscription\r\n}\r\n```\r\n\r\nThe scheduler is going to be a singleton and since every operator/combinator internally subscribes to some other sources they too pass the received scheduler to those sources. Essentially we have a single instance of the Scheduler shared across the application thus maintaining a central control over time.\r\n\r\n**Scheduler**\r\n```ts\r\nexport interface Scheduler {\r\n  setTimeout(cb: Function, relativeTime: number): Disposable\r\n  setImmediate(cb: Function): Disposable\r\n  setInterval(cb: Function, interval: number): Disposable\r\n  requestAnimationFrame(cb: Function): Disposable\r\n  now(): number\r\n}\r\n```\r\n\r\nSchedulers provide the standard javascript timing functions such as `setTimeout` , `setImmediate` etc. and also the current time of the scheduler via `now()`. The implementation of these timing functions would be left to the class that implements the  `Scheduler` interface. For instance the `DefaultScheduler` could use the actual JS event loop to asynchronously queue jobs where as a `TestScheduler` could have its own implementation of the queue using arrays that is synchronous.\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"tusharmath"}}