[RxJS] Stopping a Stream with TakeUntil
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));
[RxJS] Stopping a Stream with TakeUntil的更多相关文章
- [RxJS] Toggle A Stream On And Off With RxJS
This lesson covers how to toggle an observable on and off from another observable by showing how to ...
- [RxJS] Logging a Stream with do()
To help understand your stream, you’ll almost always want to log out some the intermediate values to ...
- [RxJS] Starting a Stream with SwitchMap & switchMapTo
From an event map to another event we can use switchMap(), switchMap() accept an function which retu ...
- [RxJS] Completing a Stream with TakeWhile
Subscribe can take three params: subscribe( (x)=> console.log(x), err=> console.log(err), ()=& ...
- [RxJS] Stopping a shared observable execution
ConnectableObservable has the connect() method to conveniently dictate the start of the shared execu ...
- RxJS v6 学习指南
为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...
- angular7 Rxjs 异步请求
Promise 和 RxJS 处理异步对比 Promise 处理异步: let promise = new Promise(resolve => { setTimeout(() => { ...
- netflix turbine概述
1.turbine是什么?它的作用是什么? Turbine is a tool for aggregating streams of Server-Sent Event (SSE) JSON data ...
- 【Pod Terminating原因追踪系列之三】让docker事件处理罢工的cancel状态码
本篇为Pod Terminating原因追踪系列的第三篇,前两篇分别介绍了两种可能导致Pod Terminating的原因.在处理现网问题时,Pod Terminating属于比较常见的问题,而本系列 ...
随机推荐
- qt 实现钟表图标
#include "clock.h" CLOCK::CLOCK(QWidget *parent) : QWidget(parent) { QTimer *timer = new Q ...
- Qt 格式化字符串
Qt字符串格式化性能比较 Qt字符串格式方法有三种, QString::arg(), QString::sprinft()和QStringList::join().今天我做了个简单的性能测试, 希望对 ...
- 文件操作2 cp mv rm
1.cp命令 [root@rusky /]# cp 123 /test #在linux系统中,如果文件123已经存在,则提示用户确认,在unix系统中则不提示,除非使用参数-i 交互式操作.cp: ...
- 使用匿名管道在进程间通信 (System.IO.Pipes使用)(转)
原文地址:http://www.cnblogs.com/yukaizhao/archive/2011/08/04/system-io-pipes.html 管道的用途是在同一台机器上的进程之间通信,也 ...
- Java Se 基础系列(笔记) -- Exception && Array
Exception 1.java 异常是java提供的用于处理程序中错误(指在程序运行的过程中发生的一些异常事件)的一种机制 2.java程序的执行过程中如果发生异常事件则自动生产一个异常类对象,该对 ...
- C++程序设计的技巧-Pimple的使用
1.Pimpl概念 在进行项目开发中可能遇到的问题,程序编译耗时很长,每一次简单修改接口之后项目都会被完全重新编译,浪费了很多时间.这个机制是Private Implementation的缩写,顾明思 ...
- uva 280 - Vertex
#include <iostream> #include <cstdio> using namespace std; #include <vector> #defi ...
- HIVE快速入门
(一)简单入门 1.创建一个表 create table if not exists ljh_emp( name string, salary float, gender string) commen ...
- php随机抽奖
貌似有些不合理,麻烦大家帮忙指正指正!谢谢~ <?php header("content-type:text/html;charset=utf-8"); function g ...
- Caffe : Layer Catalogue(2)
TanH / Hyperbolic Tangent 类型(type):TanH CPU 实现: ./src/caffe/layers/tanh_layer.cpp CUDA.GPU实现: ./src/ ...