0

I need to check if a thing exists before anything else happens. I listen for input via the eventBus like so:

    eventBus.on('element.updateId', (event) => {

        const b = async ()=> {
            return await this.checkNewId(event.newId).then()
        }

        return b();
    });

and this is the service function that needs to complete, but it doesn't complete instead it moves on to other functions - what am i doing wrong?

checkNewId(newId) {
    return this.myService.getDiagram(newId).pipe(
        tap(
            (data) => {
                this.validationErrors.next('Duplicate');
                return data;
            }, 
            (err) => {
                this.validationErrors.next('');

            }
        ),
        first()
        ).toPromise();
}

I tried to follow this example here: Subscription to promise

rubixkube
  • 97
  • 1
  • 10
  • The question is, what is your problem? You did not mention what's going wrong. –  Apr 17 '21 at 19:12
  • Your `b` function doesn't return anthing other than a Promise that resolves with `undefined`. Use `return` before `await`. – Redu Apr 17 '21 at 20:02
  • @Redu, yes you are correct, i added a return before await, thank you, but it still doesnt ever reach the validationErrors part. Is this because there are arrow functions, and if so how do i then make those complete? – rubixkube Apr 17 '21 at 20:33
  • "*instead it moves on to other functions*" - sure, it's asynchronous. What "other functions" specifically do you want to wait for the completion? – Bergi Apr 17 '21 at 21:24
  • When the eventbus listener completes, the listeners in the third party pkg code kick in and start to validate the input, so I’m trying to validate input on my end, tell it that it’s invalid before that process kicks off. – rubixkube Apr 17 '21 at 22:59

0 Answers0