My application has a service that runs an observable every time I click a button. The problem is that if I click the button several times it executes the Observable several times at the same time. He needed this service to line up and run one at a time. What better way to do this?
EDIT: Source
// component
onClick(record){
this.myService.updateRecord(params).subscribe();
}
// service
updateRecord(record){
return new Observable((observer) => {
Observable.forkJoin(
Observable.fromPromise(this.storage.get('things')),
Observable.fromPromise(this.storage.get('other_things'))
).subscribe(
(results) => {
let things = results[0] || []
let other_things = results[1] || []
// do stuffs
observer.next([record])
observer.complete()
})
})
}