vigour-io / concurrent-task

An observable to help running multiple async tasks in parallel with a concurrency limit
ISC License
0 stars 0 forks source link

Maybe interesting to use generators and struct #2

Open jimdebeer opened 7 years ago

jimdebeer commented 7 years ago

check marcus his request-generator package

const url = 'http://api.themoviedb.org'
const apikey = '&api_key=7049bfd41c073cdc48a026969d0cb3e1'
const request = require('request-generator')
const s = require('./')

var page = 1

const a = s(request(
  `${url}/3/discover/movie?sort_by=popularity.desc&page=${page}${apikey}`,
  'results.*',
  data => ({ [data.id]: data }),
  (err, cnt, req) => new Promise(resolve => {
    if (err) { console.log('err time', err) }
    req.path = `/3/discover/movie?sort_by=popularity.desc&page=${++page}${apikey}`
    setTimeout(() => resolve(), 1000)
  })
))

a.on((val) => { console.log(val && val.title) })

console.log('---')
jimdebeer commented 7 years ago

so as tasks you could use generator functions, that get re-invoked, simple api for multiple steps etc