public protocol RequestDelegate
Allows you to create
Requests with custom logic. This is useful for taking things that are not standard network
requests, and wrapping them so they look to Siesta as if they are. To create a custom request, pass your delegate to
You can also implement Siesta’s
Request protocol yourself, but this is a daunting task full of pitfalls and
redundant effort. This protocol provides customization points for only the things custom requests typically need to
customize, and provides standard behavior and sanity checks. In particular, using
- provides standard implementations for all the request hooks,
- ensures those hooks are called exactly once, even if your delegate misbehaves and reports multiple responses,
- tracks request state and ensures valid state transitions,
- polls request progress, and
- handles cancellation cleanly, preventing “response after cancel” race conditions.
Siesta itself uses this protocol to implement its own requests. Look at
RequestChainDelgate in Siesta’s source code for examples of implementing this protocol.
The delegate should commence the operation (e.g. network call) that will eventually produce a response.
Siesta will call this method at most once per call to
Implementations of this method MUST eventually call
completionHandler.broadcastResponse(...). They will typically want to hold on to the
completionHandlerfor the duration of a long-running operation in order to broadcast the response at the end.
func startUnderlyingOperation(passingResponseTo completionHandler: RequestCompletionHandler)
Returns another delegate which would perform the same underlying operation as this one. What consitutes the “same operation” is delegate-specific; for example, the new delegate may re-read relevant resource configuration.
If you never use
Request.repeated(), you can decline to implement this by calling
func repeated() -> RequestDelegate
Asks your delegate to report progress ranging from 0 to 1. Implementations may be as accurate or as inaccurate as they wish. Values returned by this method SHOULD increase monotonically.
Siesta will ensure that a
Requestreports progress of 1 when completed, regardless of what this method returns.
Returns a constant 0.
func computeProgress() -> Double