[RxJS] Stopping a Stream with TakeUntil
with stream Rxjs
2023-09-14 09:00:54 时间
Observables often need to be stopped before they are completed. This lesson shows how to use takeUntil
to stop a running timer. Then we use the starting stream and the stopping stream together to create a simple stopwatch.
const Observable = Rx.Observable; const startButton = document.querySelector('#start'); const stopButton = document.querySelector('#stop'); const start$ = Observable.fromEvent(startButton, 'click'); const interval$ = Observable.interval(1000); const stop$ = Observable.fromEvent(stopButton, 'click'); const intervalThatStops$ = interval$ .takeUntil(stop$); start$ .switchMapTo(intervalThatStops$) .subscribe((x)=> console.log(x));
相关文章
- Play with docker 1.12
- [React] Cleaning up Functional Components with Custom Hooks
- [Typescript] Extend Functionality of a TypeScript Class with Decorators
- [Recompose] Stream Props to React Children with RxJS
- [Node.js] Serve Static Files with Express
- [Ramada] Build a Functional Pipeline with Ramda.js
- [Redux] Reducer Composition with combineReducers()
- [RxJS] Stream Processing With RxJS vs Array Higher-Order Functions
- [Javascript] Avoid Nested For Loops with Generators
- [Cypress] Find Unstubbed Cypress Requests with Force 404
- [Docker] Getting Started with Container Networks
- [Javascript] Intercept property access with Javascript Proxy
- [Unit Testing] Test async function with Jasmine
- [Angular 2] Rendering an Observable Date with the Async and Date Pipes
- [RxJS] Resubscribing to a Stream with Repeat
- [RxJS] Logging a Stream with do()
- [RxJS] Aggregating Streams With Reduce And Scan using RxJS
- error C2338: You've instantiated std::aligned_storage<Len, Align> with an extended alignment (in other words, Align >
- 成功解决raise AssertionError(“Torch not compiled with CUDA enabled“)AssertionError: Torch not compiled