Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
PHP Reactive Programming

You're reading from   PHP Reactive Programming Build fault tolerant and high performing application in PHP based on the reactive architecture

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781786462879
Length 364 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Sikora Sikora
Author Profile Icon Sikora
Sikora
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

PHP Reactive Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Introduction to Reactive Programming FREE CHAPTER 2. Reactive Programming with RxPHP 3. Writing a Reddit Reader with RxPHP 4. Reactive versus a Typical Event-Driven Approach 5. Testing RxPHP Code 6. PHP Streams API and Higher-Order Observables 7. Implementing Socket IPC and WebSocket Server/Client 8. Multicasting in RxPHP and PHP7 pthreads Extension 9. Multithreaded and Distributed Computing with pthreads and Gearman 10. Using Advanced Operators and Techniques in RxPHP Reusing RxPHP Techniques in RxJS

The zip() operator


The zip() operator is similar to the ForkJoinObservable that we implemented ourselves in Chapter 5, Testing RxPHP Code. The main difference is that it internally stores all emissions for each source Observable in a separate queue and then re-emits their values when all sources have a value at a specific index.

This will be understood better by looking at the following example:

// zip_01.php 
$obs1 = Observable::range(1, 7); 
$obs2 = Observable::fromArray(['a', 'b']); 
$obs3 = Observable::range(42, 5); 
 
$obs1->zip([$obs2, $obs3]) 
  ->subscribe(new DebugSubject()); 

We have three source Observables where each of them emits a different number of items. Then the zip() operator emits an array of values only when all the sources have emissions at the same index. So we know that DebugSubject will receive only two items because the $obs2 Observable emits only two items.

In other words, the zip() operator can't make the third emission because...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images