I'm working on a function called loadMessages
that I want to return an Observable
.
loadMessages(chatId: string): Observable<Message[]> {
console.log('1');
this.autorun(() => {
const handle = this.subscribe('messages', chatId);
if (handle.ready()) {
console.log('2');
const messages = Messages.find().fetch();
return Observable.of(messages); // the return statement here is unnecessary for this function
}
});
console.log('3'); // my goal is not to immediately execute this line
// Although I wish I could return here, it's not feasible in this context
}
How can I navigate back to the function level?
Currently, the sequence of execution is 1 -> 3 -> 2. Is there a way to change this to 1 -> 2 and then pause until I receive the data?