Moya: RxSwift: requestWithProgress().filterCompleted() Call onNext twice?

Created on 21 May 2017  Â·  2Comments  Â·  Source: Moya/Moya

env:
'RxSwift', ' 3.2.0'
'Moya', ' 8.0.4'
'Moya/RxSwift', ' 8.0.4'

DLog(message: "upload image start")
TBXNetwork.provider.requestWithProgress(FileAPI.uploadImage(policy: policy, image: image).target)
.do(onNext: { (response) in
    DLog(message: String(format: "index %d - progress %lf", index, response.progress))
})
.filterCompleted()
.debug()
.mapJson()
.subscribe(
    onNext: { json in
        handler(true, (index, json["data"]["url"].string!))
    },
    onError: { error in
        DLog(message: error.localizedDescription)
        handler(false, (index, error.localizedDescription))
    },
    onCompleted: {
        DLog(message: "upload image complete")
    }
)
.addDisposableTo(self.disposeBag)

logs:

[code.swift:line:96]- upload image start
2017-05-21 16:37:56.820: code.swift:102 (uploadImage(uid:token:type:images:handler:)) -> subscribed
[code.swift:line:99]- index 0 - progress 0.124667
[code.swift:line:99]- index 0 - progress 0.748000
[code.swift:line:99]- index 0 - progress 0.872666
[code.swift:line:99]- index 0 - progress 0.872666
[code.swift:line:99]- index 0 - progress 0.997333
[code.swift:line:99]- index 0 - progress 0.997333
[code.swift:line:99]- index 0 - progress 0.997333
[code.swift:line:99]- index 0 - progress 1.000000
[code.swift:line:99]- index 0 - progress 1.000000
2017-05-21 16:37:57.934: code.swift:102 (uploadImage(uid:token:type:images:handler:)) -> Event next(Status Code: 200, Data Length: 189)
[code.swift:line:99]- index 0 - progress 1.000000
2017-05-21 16:37:57.940: code.swift:102 (uploadImage(uid:token:type:images:handler:)) -> Event next(Status Code: 200, Data Length: 189)
2017-05-21 16:37:57.942: code.swift:102 (uploadImage(uid:token:type:images:handler:)) -> Event completed
[code.swift:line:115]- upload image complete
2017-05-21 16:37:57.942: code.swift:102 (uploadImage(uid:token:type:images:handler:)) -> isDisposed

why this code call onNext twice?
when i repalce requestWithProgress with request,
or add .skip(1) before .subscribe,
it work as expected.
anybody can answer my question? i will be grateful.

question rxmoya

Most helpful comment

Hey @Re-cover! Thank you so much for filling in an issue.

I'm investigating it and seems like a problem on our end. I have a fix for that already, just need to write some tests. Gonna reference it here once I do the PR.

All 2 comments

Hey @Re-cover! Thank you so much for filling in an issue.

I'm investigating it and seems like a problem on our end. I have a fix for that already, just need to write some tests. Gonna reference it here once I do the PR.

I've made a PR with the fix, #1095. I'm gonna close this one in favor of this PR. If you'd still have the problem after this PR is merged, please reopen this issue. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

syq7970 picture syq7970  Â·  3Comments

GurpalRajput picture GurpalRajput  Â·  3Comments

pedrovereza picture pedrovereza  Â·  3Comments

hjzCy picture hjzCy  Â·  3Comments

mwawrusch picture mwawrusch  Â·  3Comments