Interruptible queuing system for closures
on cue - a signal for action
A way to run tasks one after the other. (with support for canceling tasks)
- Hard to queue up tasks that needs to be preformed one after the other
- Hard to unit-test network code
- Async network code all over the place is hard to reason about and hard to make bug free
- Features such as
timeout
andretry
are hard to build into DispatchWorkItem or NSOperationQueue
- Ability to add and remove items to the queue
- The Queue should be able to be run from start to finish
- Has tasks that can .start() and .stop() and has .onComplete() callback
- Tasks should have the ability to support timeout and retry
- The Queue should be able to paused/stopped, resumed/started, reset/canceled (
β οΈ οΈ resume is not supported, only cancelβ οΈ οΈ) - Queues should be able to be nested? Queues within queues? (maybe) (reach-goal,
β οΈ οΈ not currently supportedβ οΈ οΈ) π€
let networkTasks: [NetworkTask] = (0..<5).map { _ in // Create 5 network tasks
.init { (_ value: Any?) in
guard let strValue: String = (value as? Data)?.stringUTF8 else { XCTFail(); return }
Swift.print("strValue: \(strValue) β¨")
}
} // For loop network task
let queue: Queue = .init()
queue.onComplete = {
Swift.print("queue test completed β
")
expectation.fulfill() // If this line is called, then test passed
}
queue.enqueue(networkTasks) // Add tasks and begin executing
- Look at pagination service project for mock-api inspo β
- Take a look at TestRunner (it has FIFO style architecture) β
- Add timeout callback? β (would need to separate network and db transaction in one task, in order to cancel transaction if network task is not complete etc) (can use Dispatchueue with timeout ?)
- Do research on other cancelable closures in swift. β There should be another one in your dispatch research etc (DispatchWorkItem)
- Do tests with timers and background calls etc β
- Test with
run
,add
andcancel
buttons π - Explain some of the use cases
- Maybe subclass NSOperation (investigation needed) see issues β¨
- Add support for result type? instead of just Any?
- Add hasNext() like TestRunner? π«