question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Split creation functions from creation functions with Schedulers

See original GitHub issue

Currently we have creation functions like so:

  • from(obj) and from(obj, scheduler)
  • range(a, b) and range(a, b, scheduler)
  • (… and many more)

Problem

Schedulers and scheduling adds a LOT of bloat to bundles and we can’t currently avoid it.

If you look at the implementations of these you’ll see an obvious pattern, especially in the ones I more recently created as “just functions”:

function fromSomething<T>(something: Something<T>, scheduler?: IScheduler) {
  if (!scheduler) {
     return new Observable(/* a little bit of code */);
  } else {
    return new Observable<T>(subscriber => {
      /* OMG WHAT?!! A HUGE MOUNTAIN OF CODE AND A BUNCH OF TYPES
          WE NEED TO IMPORT FOR THIS SO WE CAN DO THINGS
          WITH SCHEDULERS, WHICH DON'T GET USED 95% OF THE TIME */
    });
  }
}

/* MORE STUFF DOWN HERE FOR SCHEDULING SUPPORT */
function dispatch() {
  /* you get the idea */
}

Proposal

  • Split creation methods into “normal” and “scheduled” flavors: from and fromScheduled, defer and deferScheduled, range and rangeScheduled etc.

If we do this, then the majority of RxJS usage (which doesn’t involve schedulers) can avoid pulling in scheduler-related classes and scheduling-related logic.

That would make the above into:

95% use case

function fromSomething<T>(something: Something<T>) {
     return new Observable(/* a little bit of code */);
}

and else where

5% use case

function fromSomethingScheduled<T>(something: Something<T>, scheduler: IScheduler) {
    return new Observable<T>(subscriber => {
      /* OMG WHAT?!! A HUGE MOUNTAIN OF CODE AND A BUNCH OF TYPES
          WE NEED TO IMPORT FOR THIS SO WE CAN DO THINGS
          WITH SCHEDULERS, WHICH DON'T GET USED 95% OF THE TIME */
    });
}

/* MORE STUFF DOWN HERE FOR SCHEDULING SUPPORT */
function dispatch() {
  /* you get the idea */
}

Risks

It will be a breaking change for people using schedulers today. Easy to fix, but annoying.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
benleshcommented, Jan 26, 2018

Plus if fns are separated, what’s recommended pattern to inject testscheduler for observables?

That wouldn’t change… from(whatever) with no Scheduler would never need a TestScheduler.

The change proposed above would obviously not include things like timer and interval.

0reactions
benleshcommented, Oct 2, 2019

Done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatic Assignment Split
If the conditions for an automatic assignment split are met, the system splits the assignment and creates one or more assignments for the...
Read more >
Why does a split occur per schedule line for ...
This can be caused by a change to system behaviour brought about by enhancing delivery creation functions: System behavior up to Release 3.1I:...
Read more >
Introduction to RTOS - Solution to Part 3 (Task Scheduling)
FreeRTOS allows us to set priorities for tasks, which allows the scheduler to preempt lower priority tasks with higher priority tasks.
Read more >
MICROSOFT PROJECT TASK SPLITTING
Microsoft Project has a function that allows multiple splits in tasks which ... A manually created split is removed by dragging the split...
Read more >
Creating and using schedules
Generate and validate schedules in the System Scheduler > Schedules menu. Note: The legacy functions that you may have used, on the System ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found