当前位置:网站首页>Learning notes of rxjs takeuntil operator
Learning notes of rxjs takeuntil operator
2022-06-25 09:46:00 【51CTO】
TakeUntil The official documentation for this operator is :
Emit values until provided observable emits.
That is, it can be given another anchoring role Observable, When the anchor Observable emit When the value of , The original Observable Just stop firing , Get into complete operation .
Look at a practical example :
source Observable Every 1 Second time interval , Launch one from 0 The start increment interval is 1 Integer sequence of .
We constructed a timer Observable, The timeout interval is 5 second , in other words , At the fifth second , The Observable Will send a value . This timer Observable Pass in takeUntil, As a notification Observable, Five seconds later ,source Observable Will stop firing integers .
Finally, the output of the above program execution :4 Print in seconds 0~4, Then the end .

Another example :
In this case ,interval As a primitive Observable,clicks As notification Observable, The expression of the whole program is , Every 1 The second has an increment 1 Integer sequence printing , Until a click event occurs on the page , original interval Observable End .
Look at another example :
Let's analyze the logic of this example line by line :
Generate an interval 1 An even number of seconds Observable.
Accumulate the number of even numbers generated .
When the number of even numbers generated is greater than 5 when , Emission value . This Observable As takeUntil Of notification Observable Use .
- Use eventSource and eventNumberCount, adopt
withLatestFromPut two Observable Connect , Thus in map Operator in , You can print the even value and even total amount of the current emission at the same time . adopt takeUntil Pass in one only if the total number of even numbers is greater than 5 When the value is emitted Observable, The total number of even numbers can be greater than 5 after , Give Way interval Stop sending values .
The final execution effect :

边栏推荐
- Question B of the East China Cup: how to establish a population immune barrier against novel coronavirus?
- Is it safe to open an account in a mobile phone or a securities company?
- Tiktok brand goes to sea: both exposure and transformation are required. What are the skills of information flow advertising?
- Study on correlation of pumpkin price and design of price prediction model based on BP neural network
- 2021mathorcupc topic optimal design of heat dissipation for submarine data center
- [IOU] intersection over union
- 汇付国际为跨境电商赋能:做合规的跨境支付平台!
- Reza RA series - development environment construction
- Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
- I put a two-dimensional code with rainbow candy
猜你喜欢

A game WP

puzzle(019.2)六边锁

How to "transform" small and micro businesses (II)?

Study on correlation of pumpkin price and design of price prediction model based on BP neural network

Mengyou Technology: tiktok live broadcast with goods elements hot topics retention skills shaping image highlight selling points
![[buuctf.reverse] 117-120](/img/6c/8a90fff2bd46f1494a9bd9c77eeafc.png)
[buuctf.reverse] 117-120

Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts

将jar包注册为服务,实现开机自动启动
![[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition](/img/b4/84c30ed112c4dffd8d51697b2f4a4f.jpg)
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition

可穿戴设备或将会泄露个人隐私
随机推荐
[design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)
Japanese online notes for postgraduate entrance examination (9): composition template
[MySQL learning notes 20] MySQL architecture
【mysql学习笔记20】mysql体系结构
股票在线开户安全吗?找谁可以办理?
[buuctf.reverse] 121-125
Cassava tree disease recognition based on vgg16 image classification
Download the arm64 package of Debian on X86 computer
Atguigu---18-component
[IOU] intersection over union
[learn C from me and master the key to programming] insertion sort of eight sorts
Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!
[buuctf.reverse] 117-120
Abbreviations of common English terms for IC R & D
华泰证券在上面开户安全吗?靠谱吗?
Solution to the problem of repeated startup of esp8266
Cocopod error failed: undefined method `map 'for nil:nilclass
Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
Lvs-dr mode single network segment case
Rxjs TakeUntil 操作符的学习笔记