This doesn't seem like the correct way to do this, but it does work. Is there a "rxjs" way to make synchronous code into asynchronous code so that my observer can return before I start processing the data? The only way I could think of doing this was to put the process within a Promise.
@Component({})
export class MyClass {
public processData() {
const sub = new BehaviorSubject<number>(0)
new Promise(() => {
let c = 0
let completionPercentage = 0
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++, c++) {
// Do some calculations
// Then compute completion percentage
sub.next(completionPercentage)
}
}
})
return sub.asObservable()
}
}