-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy patha_plus_b.js
More file actions
28 lines (19 loc) · 731 Bytes
/
a_plus_b.js
File metadata and controls
28 lines (19 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let {Observable} = require('rxjs/Observable');
require('rxjs/add/observable/interval');
require('rxjs/add/observable/from');
require('rxjs/add/operator/combineLatest');
require('rxjs/add/operator/zip');
/*
let a1 = 2;
let b1 = 4;
let c1 = a1 + b1; // c1 = 6
a1 = 55; // c1 = 6;
b1 = 20; // c1 = 6;
*/
const a1$ = Observable.from([2, 55])
.zip(Observable.interval(1200), x => x); // emit 2 and 55 1.2 sec apart
const b1$ = Observable.from([4, 20])
.zip(Observable.interval(2000), x => x); // emit 4 and 20 two sec apart
// combine latest emits when either observable produces data
a1$.combineLatest(b1$, (x, y) => x + y)
.subscribe(val => console.log(`a1+b1 = ${val}`));