Skip to content

Commit f031611

Browse files
demenskybenlesh
authored andcommitted
feat(throwError): removed deprecated throwError(errorFactory, scheduler) call pattern
BREAKING CHANGE: `throwError(errorFactory, scheduler)` call pattern is no longer available. [Read more](https://rxjs.dev/deprecations/scheduler-argument).
1 parent f140eee commit f031611

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

spec-dtslint/observables/throwError-spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { throwError, animationFrameScheduler } from 'rxjs';
1+
import { throwError } from 'rxjs';
22

33
it('should error for incorrect errorFactory', () => {
44
const a = throwError(1); // $ExpectError
@@ -12,7 +12,3 @@ it('should accept any type and return never observable with support of factory',
1212
const c = throwError(() => ({ a: 1 })); // $ExpectType Observable<never>
1313
const d = throwError(() => ({ a: 2 })); // $ExpectType Observable<never>
1414
});
15-
16-
it('should support a factory and a scheduler', () => {
17-
const a = throwError(() => 1, animationFrameScheduler); // $ExpectType Observable<never>
18-
});

spec/observables/throwError-spec.ts

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ describe('throwError', () => {
3434
});
3535
});
3636

37-
it('should accept scheduler', () => {
38-
rxTest.run(({ expectObservable }) => {
39-
const e = throwError(() => 'error', rxTest);
40-
41-
expectObservable(e).toBe('#');
42-
});
43-
});
44-
4537
it('should accept a factory function', () => {
4638
let calls = 0;
4739
let errors: any[] = [];

src/internal/observable/throwError.ts

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Observable } from '../Observable';
2-
import { Subscriber } from '../Subscriber';
3-
import { SchedulerLike } from '../types';
42

53
/**
64
* Creates an observable that will create an error instance and push it to the consumer as an error
@@ -94,20 +92,8 @@ import { SchedulerLike } from '../types';
9492
*
9593
* @param errorFactory A factory function that will create the error instance that is pushed.
9694
*/
97-
export function throwError(errorFactory: () => any): Observable<never>;
98-
99-
/**
100-
* Notifies the consumer of an error using a given scheduler by scheduling it at delay `0` upon subscription.
101-
*
102-
* @param errorFactory An error instance or error factory
103-
* @param scheduler A scheduler to use to schedule the error notification
104-
* @deprecated The `scheduler` parameter will be removed in v8.
105-
* Use `throwError` in combination with {@link observeOn}: `throwError(() => new Error('test')).pipe(observeOn(scheduler));`.
106-
* Details: https://rxjs.dev/deprecations/scheduler-argument
107-
*/
108-
export function throwError(errorFactory: () => any, scheduler: SchedulerLike): Observable<never>;
109-
110-
export function throwError(errorFactory: () => any, scheduler?: SchedulerLike): Observable<never> {
111-
const init = (subscriber: Subscriber<never>) => subscriber.error(errorFactory());
112-
return new Observable(scheduler ? (subscriber) => scheduler.schedule(init as any, 0, subscriber) : init);
95+
export function throwError(errorFactory: () => any): Observable<never> {
96+
return new Observable((subscriber) => {
97+
subscriber.error(errorFactory());
98+
});
11399
}

0 commit comments

Comments
 (0)