how to use the never function from the rxjs library in javascript

The never function from the rxjs library creates an observable that does not emit anything and never completes.

You can import it from the library and use it like this:

index.tsx
import { never } from 'rxjs';

const obs = never();

obs.subscribe(
  value => console.log(value),
  error => console.error(error),
  () => console.log('Completed')
);

// Output: (nothing happens)
198 chars
12 lines

The subscribe method is called, but since never does not emit anything and never completes, none of the callbacks are executed. This is useful when you need to create an observable that just waits for some external event to trigger something, but you want to handle the subscription before that event occurs.

gistlibby LogSnag