Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chained request progress #299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Source/Siesta/Request/RequestChaining.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ public enum RequestChainAction
case useThisResponse
}

internal struct RequestChainDelgate: RequestDelegate
internal class RequestChainDelgate: RequestDelegate
{
typealias ActionCallback = (ResponseInfo) -> RequestChainAction

let requestDescription: String

private let wrappedRequest: Request
private let determineAction: ActionCallback

private var nextRequestProgress: Double?

init(wrapping request: Request, whenCompleted determineAction: @escaping ActionCallback)
{
Expand Down Expand Up @@ -126,10 +128,14 @@ internal struct RequestChainDelgate: RequestDelegate
request.start() // Necessary if we are passing to deferred original request
request.onCompletion
{ completionHandler.broadcastResponse($0) }
request.onProgress
{ progress in self.nextRequestProgress = progress }
}
}

// TODO: progress reporting
func computeProgress() -> Double {
return nextRequestProgress ?? wrappedRequest.progress
}

func repeated() -> RequestDelegate
{
Expand Down