angular - Rxjs observable batch before execute -
i'm trying build function get's id , send server , return response. far good.. issue function may called lot of times, want achieve following: function get's id, wait 3 seconds , execute. if id been passed during 3 seconds, append to id's sent , start 3 seconds count again. after 3 seconds pass, send id's (in single request) , return response every id sender.
so far try use subject , buffer operator :
batchplacebetsubscription:subject<string>=new subject(); batchplacebetsubscription:observable<response>; sendtoserver(id: string): observable<any> { this.batchplacebetsubscription.next(id); return this.batchplacebetsubscription$; } private placebetbatchrequests(placebetitem: iplacebet[]) { this.batchplacebetsubscription$ = this.batchplacebetsubscription .buffer(observable.timer(0, 3000)) .take(1) .switchmap(idsarray => { debugger; return this.http.post('http://someurl,idsarray) .map(res => res.json()) .catch(e => observable.throw(e)) }) } this work's first id been ignored (i guess because when subject 'next' it, there not subscribers yet).
so, how can batch id's? in advance.
Comments
Post a Comment