Search code examples
swiftmoyareactive-swift

moya request in background thread


I'm wondering how to make a request in a background thread, what I mean by that is the fetching in a background thread and then come back to the main thread

Currently I can go the main thread after the request by calling:

.observe(on: UIScheduler())

But I didn't succeeded to make the request in another thread, you think it's a good idea to make it in another thread ?


Solution

  • Assuming you have a SignalProducer, you can use the start(on:) operator so that it's start() method is run on a different scheduler. So you could do producer.start(on: QueueScheduler()) to ensure it is started asynchronously on a GCD queue.