#rxjs

14 messages · Page 1 of 1 (latest)

hushed adder
#

Just explored rxjs, so is rxjs mandatory to use in nestjs's services? or i can just write normal code? any special benifits i will get while using rxjs insted of normal async code?

little lagoon
#

it is not mandatory

hushed adder
#

so basically with rxjs i can do this

getAllUsers(): Observable<User[]> {
    return from(this.usersRepository.find()).pipe(
      catchError((err) =>
        throwError(() => {
          this.logger.error()
          throw new InternalServerErrorException('Could not fetch users.');
        }),
      ),
    );
  }

While with normal async i can do this

async getAllUsers(): Promise<User[]> {
    return this.usersRepository.find();
  }

So as per this, i understood that i can handle the errors in a better way with rxjs so only this is the pros of rxjs or there is any other??

little lagoon
#

I'm not that into rxjs so I can't tell much about the 'special benifits'
It just another tool that you can use for promises on steroids (as they say)
You can do much more than just error handling with it

#

I guess they are pretty common in angular world

hushed adder
#

its just like effects.ts ?

little lagoon
#

not sure
rxjs came first tho

#

they are not the same

hushed adder
#

ohh

#

got it

#

thanks for the help!

round blaze
#

Effect is basically RxJS + Result pattern (in my short experience with it)