Moya: Request never starts inside flatMapLatest

Created on 13 Nov 2017  路  2Comments  路  Source: Moya/Moya

Hey everybody!
I use Moya 10.0.0 and Moya Model Mapper.

I'll try to do soemthing like that:

private func getDataFromServer() -> Observable<DataModel> {

  return loadIDFromDB().flatMapLatest { id_Data -> Observable<DataFromServer> in
    let provider = MoyaProvider<CustomEndpoint>()
    return provider.rx.request(.GetData(id_Data ))
     .debug()
     .mapJSON()
     .asObservable()
   }.map{ jsonData -> DataFromServer in
      return self.mapData(jsonData)
   }
}

func loadData() {

  getDataFromServer().subscribe {
    // DO SOMETHING
  }.disposed(by:db)

}

The debug output states that it gets subscribed, but there is never a server call.
If I would just subscribe instead of flatmapLatest and then subscribe again inside the subscribe and store the data in a Variable it works. But this is no real solution for me.

Maybe I am getting something wrong with Rx? But usually this works for me.

Any ideas?

Kind regards!

question

Most helpful comment

Hey @bweickert,
I think you need to be keeping a reference to your MoyaProvider outside of the function body
Docs: https://github.com/Moya/Moya/blob/master/docs/Providers.md
Related: https://github.com/Moya/Moya/pull/1386

All 2 comments

Hey @bweickert,
I think you need to be keeping a reference to your MoyaProvider outside of the function body
Docs: https://github.com/Moya/Moya/blob/master/docs/Providers.md
Related: https://github.com/Moya/Moya/pull/1386

Awesome! Thank you very much @SD10! That was the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GurpalRajput picture GurpalRajput  路  3Comments

cocoatoucher picture cocoatoucher  路  3Comments

holysin picture holysin  路  3Comments

pedrovereza picture pedrovereza  路  3Comments

Tynox picture Tynox  路  3Comments