aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/rxjs/src/internal/observable/empty.ts
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-06-28 17:26:46 -0700
committerPinapelz <yukais@pinapelz.com>2025-06-28 17:43:56 -0700
commite4fa1e69e7ebfb627c7198fd1a9881e9327ec4d4 (patch)
tree06284a538a6008eca75051399e47db4e5d50301c /node_modules/rxjs/src/internal/observable/empty.ts
initial commit: scaffolding
Diffstat (limited to 'node_modules/rxjs/src/internal/observable/empty.ts')
-rw-r--r--node_modules/rxjs/src/internal/observable/empty.ts79
1 files changed, 79 insertions, 0 deletions
diff --git a/node_modules/rxjs/src/internal/observable/empty.ts b/node_modules/rxjs/src/internal/observable/empty.ts
new file mode 100644
index 0000000..8f59e45
--- /dev/null
+++ b/node_modules/rxjs/src/internal/observable/empty.ts
@@ -0,0 +1,79 @@
+import { Observable } from '../Observable';
+import { SchedulerLike } from '../types';
+
+/**
+ * A simple Observable that emits no items to the Observer and immediately
+ * emits a complete notification.
+ *
+ * <span class="informal">Just emits 'complete', and nothing else.</span>
+ *
+ * ![](empty.png)
+ *
+ * A simple Observable that only emits the complete notification. It can be used
+ * for composing with other Observables, such as in a {@link mergeMap}.
+ *
+ * ## Examples
+ *
+ * Log complete notification
+ *
+ * ```ts
+ * import { EMPTY } from 'rxjs';
+ *
+ * EMPTY.subscribe({
+ * next: () => console.log('Next'),
+ * complete: () => console.log('Complete!')
+ * });
+ *
+ * // Outputs
+ * // Complete!
+ * ```
+ *
+ * Emit the number 7, then complete
+ *
+ * ```ts
+ * import { EMPTY, startWith } from 'rxjs';
+ *
+ * const result = EMPTY.pipe(startWith(7));
+ * result.subscribe(x => console.log(x));
+ *
+ * // Outputs
+ * // 7
+ * ```
+ *
+ * Map and flatten only odd numbers to the sequence `'a'`, `'b'`, `'c'`
+ *
+ * ```ts
+ * import { interval, mergeMap, of, EMPTY } from 'rxjs';
+ *
+ * const interval$ = interval(1000);
+ * const result = interval$.pipe(
+ * mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : EMPTY),
+ * );
+ * result.subscribe(x => console.log(x));
+ *
+ * // Results in the following to the console:
+ * // x is equal to the count on the interval, e.g. (0, 1, 2, 3, ...)
+ * // x will occur every 1000ms
+ * // if x % 2 is equal to 1, print a, b, c (each on its own)
+ * // if x % 2 is not equal to 1, nothing will be output
+ * ```
+ *
+ * @see {@link Observable}
+ * @see {@link NEVER}
+ * @see {@link of}
+ * @see {@link throwError}
+ */
+export const EMPTY = new Observable<never>((subscriber) => subscriber.complete());
+
+/**
+ * @param scheduler A {@link SchedulerLike} to use for scheduling
+ * the emission of the complete notification.
+ * @deprecated Replaced with the {@link EMPTY} constant or {@link scheduled} (e.g. `scheduled([], scheduler)`). Will be removed in v8.
+ */
+export function empty(scheduler?: SchedulerLike) {
+ return scheduler ? emptyScheduled(scheduler) : EMPTY;
+}
+
+function emptyScheduled(scheduler: SchedulerLike) {
+ return new Observable<never>((subscriber) => scheduler.schedule(() => subscriber.complete()));
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage