Skip to content

Instantly share code, notes, and snippets.

@homam
Last active September 21, 2015 09:26
Show Gist options
  • Select an option

  • Save homam/4bf3c736b98fae4fd0c1 to your computer and use it in GitHub Desktop.

Select an option

Save homam/4bf3c736b98fae4fd0c1 to your computer and use it in GitHub Desktop.
stress test pipe rxjs
{Observable, AsyncSubject} = require \Rx
request = require \request
{sum} = require \prelude-ls
log-source = (source) ->
source.subscribe do
(x) ->
console.log \x, x
(err) ->
console.log \err, err
->
console.log \done
epoch = new Date "2015-09-17Z"
date-from = epoch
date-to = new Date (epoch.value-of! + 6 * 3600 * 1000)
to-interval = (start, end, interval) -->
[(new Date (start.value-of! + interval) .toJSON!), (new Date (end.value-of! + interval) .toJSON!)]
load-source = (branch-id, [date-from, date-to]) ->
subject = new AsyncSubject!
do ->
err, r, body <- request.get "http://192.168.1.42:4081/apis/branches/#{branch-id}/execute/1000/transformation?campaignId=16944&dateFrom=#{date-from}&dateTo=#{date-to}"
subject.on-next {date-from, date-to, body: JSON.parse body}
subject.on-completed!
subject.asObservable!
load-sources = ([date-from, date-to]:range) ->
Observable.from <[poJiT0U porWwCl poqBANR]>
.concatMap (branch-id) -> load-source branch-id, range
source = Observable.interval 250 .time-interval! .map (-> 25 * 1000) .scan do
(a, b) -> a + b
0
.map (to-interval date-from, date-to)
.concatMap load-sources
log-source source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment