Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Created May 5, 2020 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshtonic/8c98c123a5c88853f4dc0b710b6ecb56 to your computer and use it in GitHub Desktop.
Save freshtonic/8c98c123a5c88853f4dc0b710b6ecb56 to your computer and use it in GitHub Desktop.
Only runs first Future
public func setupScript(tag: NFCISO7816Tag) -> AnyPublisher<CommandResult, Error> {
return Deferred { Future<CommandResult, Error> { promise in
print("C 1");
tag.sendCommand(apdu: commandWriteDataUrlTemplate(), completionHandler: commandCallback(promise))
}}.flatMap { _ in
return Deferred{ Future<CommandResult, Error> { promise in
print("C 2");
tag.sendCommand(apdu: commandAuthenticateEV2FirstPart1(), completionHandler: commandCallback(promise))
}
}}.flatMap { result in
return Deferred { Future<CommandResult, Error> { promise in
print("C 3");
tag.sendCommand(apdu: commandAuthenticateEV2FirstPart2(result), completionHandler: commandCallback(promise))
}}
}
.eraseToAnyPublisher()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment