Wait async subscriptions when I emit next value #6701
Unanswered
NaumovEvgeniy
asked this question in
Q&A
Replies: 1 comment 1 reply
-
That's just.... imposible as you're doing it? What's your actual purpose? Your code is equivalent to: console.log('>>> START')
new Promise(res => {
setTimeout(() => {
console.log('!! 1');
res(undefined)
}, 500);
})
new Promise(res => {
setTimeout(() => {
console.log('!! 2');
res(undefined)
}, 1000);
})
console.log('<<< FINISH') Which will of course log 1 and 2 after "FINISH". I can suggest something to "fix" it, which would be: import { Subject } from "rxjs";
const subject = new Subject();
subject.subscribe(() => console.log('!! 1'))
subject.subscribe(() => console.log('!! 2'))
console.log('>>> START')
subject.next(undefined);
console.log('<<< FINISH') This will output what you want, but I'm sure it's not the answer you're looking for... What do you want to achieve? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have the next example
Console looks like
Can I reach expected behaviour or I should to use another aproach? I've digged into a source code, but I could not find solutions for me.
Beta Was this translation helpful? Give feedback.
All reactions