Meteor Server Side with RxJS

Hi everyone,
I’ve been making a server side application with Meteor, but I’ve taken RxJS into the fold, it’s because I love how RxJS standardized there syntax and usage across languages implementation. Plus that, Meteor seems to be kinda “reactive” solution.

But I’ve been hitting with this problem when using RxJS with meteor/http's HTTP.call as per image

The code that cause problem

someMethodsThatCallHTTPCall() {
    return Observable.create(observer => {
        HTTP.call('path', (err, res) => {
                  // Some processing
        })
    }
}

I’ve done some other googling and try out. All these combination.

Bind on callback, same error on the same line as HTTP

someMethodsThatCallHTTPCall() {
    return Observable.create { observer in
        HTTP.call('path', Meteor.bindEnvironment((err, res) => {
                  // Some processing
        }))
    }
}

This produce error on the Meteor.bindEnvironment call

someMethodsThatCallHTTPCall() {
    return Observable.create(observer => {
        const callback = Meteor.bindEnvironment((err, res) => {
                  // Some processing
        })
        HTTP.call('path', callback)
    }
}

This also produce the same error

someMethodsThatCallHTTPCall() {
    return Observable.create(observer => {
        Meteor.bindEnvironment(() => {
                HTTP.call('path', (err, res) => {
                          // Some processing
                })
        })
    }
}

I’ve also tried the wrapAsync variants and ended up the same

Can anyone help me on this? Or it’s just that I’m not supposed to use RxJS with Meteor on the server side at all?

NOTE: This happened when there’s 2 subsequent call related to to meteor as-in

theFirstFunction() {
       return Observable.create(observer => {
              // Some async processing that yields element
       }).do(o => this.saveData(o))
}

saveData(_ o: any) {
      // Data here is actually Meteor's Mongo Collection, but it went fine here
      Data.rawCollection.update({}, o)
}

someMethodsThatCallHTTPCall() {
      // The implementation as i've mention above
}

functionThatGetsCalled() {
      this.otherObservable().pipe(
             tap(() => {}),
             catchError(() => anotherObservable()),
             catchError(() => theFirstFunction())
      ).flatMap(this.someMethodsThatCallHTTPCall) // << here's the problematic functio
}

// Some where else in the code
functionThatGetsCalled().subscribe()

Much obliged.

Its a bit late here, but what if you try this:

someMethodsThatCallHTTPCall() {
    return Observable.create(Meteor.bindEnvironment(observer => {      
         HTTP.call('path', (err, res) => {
             // Some processing
         })
    )}
}
1 Like

Also you might want to use fetch as HTTP package is going to be deprecated soon.

2 Likes

Hey, hello, thanks for the note. Is it going to really be deprecated? I tried searching for deprecation (Googling) didn’t find any, Do you have to link to the deprecation.

Thanks this seems to be working, I’m having this running in various way now. (e.g. Nested callback outside of meteor)