Utilizing rxjs, I am wondering if there is a way to trigger the next function only when the observable has completed. Rather than the nested structure below:
this.Start(data).subscribe(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
this.nextFunction()
.subscribe(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
this.nextFunction2()
.subscribe(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
this.nextFunction3()
.subscribe(...)
}
);
}
);
}
);
Is there a way to handle it more elegantly like this:
this.Start(data).subscribe(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
return other observable;
}
)
.then(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
return other observable;
}
)
.then(
(data) => {
console.log('next');
},
(err) => {
console.log('err');
},
() => {
console.log('complete');
return other observable;
}
);
I aim to avoid creating a pyramid-like structure in my code.