Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.js"></script>
</head>
<body>
</body>
</html>
 
const Observable = Rx.Observable;
const Subject = Rx.Subject;
let subject = new Subject();
const response = {
  start_time: new Date(),
  end_time: new Date(),
  radio_show: {
    id: 0,
    name: "Loading..."
  }
};
let radioShow$ = Observable.defer(() => {
    // return http.get(...);
    return Observable.of(response);
  })
  .do(() => console.log('create new HTTP request'))
  .repeatWhen(() => subject)
  .publishReplay()
  .refCount();
// responses
radioShow$
  .startWith(response)
  .subscribe(val => console.log('Response:', val));
// pooling delay
radioShow$
  .map(response => { // calculate the delay
    // return response.end_time - (new Date()).getTime();
    return Math.random() * 1000;
  })
  .concatMap(delay => Observable.of(null).delay(delay))
  .subscribe(subject);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
martinsikpro
0viewers