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@%5E7/dist/bundles/rxjs.umd.min.js"></script>
</head>
<body>
</body>
</html>
 
console.clear()
console.log('start')
const { Subject } = rxjs
const { concatMap, mergeMap, switchMap, map } = rxjs.operators
const subject = new Subject()
subject
  .pipe(
    concatMap(obj => { // concatMap, mergeMap, switchMap で結果が変わる
      return httpGet(obj.url, obj.delay)
    }),
    map(res => JSON.parse(res).ResultData)
  )
  .subscribe(value => {
    console.log(value)
  })
subject.next({ url: 'http://foo', delay: 500 })
subject.next({ url: 'http://bar', delay: 300 })
subject.next({ url: 'http://baz', delay: 100 })
function httpGet(url, delay) {
  return new Promise(resolve => {
    setTimeout(() => {
      const obj = { ResultData: url + ' -> resolved' }
      resolve(JSON.stringify(obj))
    }, delay)
  })
}
Output

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

Dismiss x
public
Bin info
ovrmrwpro
0viewers