I don't see very good documentation on what the difference is between do
and finally
in RxJS. My goal is to take action only when an Observable returns data but it looks like they will both take action on failure as well.
do
says "Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence."
The observable might return more than one element?
finally
says "Invoke a specified action after the source observable sequence terminates gracefully or exceptionally".
My hope is that someone will explain if it matters which is used or if there is a better alternate method.
getData(choice): void {
this.dataService.getTableData(choice, 'mainCalls.php')
.do( () => this.defineWidth() )
.subscribe(tableData => this.tableData = tableData,
err => {
console.log(err);
}
);
}
ngOnInit() {
this.getData('getTableData');
}
defineWidth is a function that is dependent upon the data being returned by the Observable. I'm open to suggestion and reading material on alternate methods to accomplish what I want.