Merge pull request #1030 from LukasKorba/1029-AsyncThrowingStream-update-so-it-does-not-use-Task
[#1029] AsyncThrowingStream update so it doesn't use Task
This commit is contained in:
commit
b582e1e4e1
|
@ -164,18 +164,15 @@ extension LightWalletGRPCService: LightWalletService {
|
||||||
|
|
||||||
func blockRange(_ range: CompactBlockRange) -> AsyncThrowingStream<ZcashCompactBlock, Error> {
|
func blockRange(_ range: CompactBlockRange) -> AsyncThrowingStream<ZcashCompactBlock, Error> {
|
||||||
let stream = compactTxStreamer.getBlockRange(range.blockRange())
|
let stream = compactTxStreamer.getBlockRange(range.blockRange())
|
||||||
|
var iterator = stream.makeAsyncIterator()
|
||||||
return AsyncThrowingStream { continuation in
|
|
||||||
Task {
|
return AsyncThrowingStream() {
|
||||||
do {
|
do {
|
||||||
for try await block in stream {
|
guard let block = try await iterator.next() else { return nil }
|
||||||
continuation.yield(ZcashCompactBlock(compactBlock: block))
|
return ZcashCompactBlock(compactBlock: block)
|
||||||
}
|
} catch {
|
||||||
continuation.finish()
|
let serviceError = error.mapToServiceError()
|
||||||
} catch {
|
throw ZcashError.serviceBlockRangeFailed(serviceError)
|
||||||
let serviceError = error.mapToServiceError()
|
|
||||||
continuation.finish(throwing: ZcashError.serviceBlockRangeFailed(serviceError))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,29 +217,24 @@ extension LightWalletGRPCService: LightWalletService {
|
||||||
utxoArgs.startHeight = UInt64(height)
|
utxoArgs.startHeight = UInt64(height)
|
||||||
}
|
}
|
||||||
let stream = compactTxStreamer.getAddressUtxosStream(args)
|
let stream = compactTxStreamer.getAddressUtxosStream(args)
|
||||||
|
var iterator = stream.makeAsyncIterator()
|
||||||
return AsyncThrowingStream { continuation in
|
|
||||||
Task {
|
return AsyncThrowingStream() {
|
||||||
do {
|
do {
|
||||||
for try await reply in stream {
|
guard let reply = try await iterator.next() else { return nil }
|
||||||
continuation.yield(
|
return UTXO(
|
||||||
UTXO(
|
id: nil,
|
||||||
id: nil,
|
address: reply.address,
|
||||||
address: reply.address,
|
prevoutTxId: reply.txid,
|
||||||
prevoutTxId: reply.txid,
|
prevoutIndex: Int(reply.index),
|
||||||
prevoutIndex: Int(reply.index),
|
script: reply.script,
|
||||||
script: reply.script,
|
valueZat: Int(reply.valueZat),
|
||||||
valueZat: Int(reply.valueZat),
|
height: Int(reply.height),
|
||||||
height: Int(reply.height),
|
spentInTx: nil
|
||||||
spentInTx: nil
|
)
|
||||||
)
|
} catch {
|
||||||
)
|
let serviceError = error.mapToServiceError()
|
||||||
}
|
throw ZcashError.serviceFetchUTXOsFailed(serviceError)
|
||||||
continuation.finish()
|
|
||||||
} catch {
|
|
||||||
let serviceError = error.mapToServiceError()
|
|
||||||
continuation.finish(throwing: ZcashError.serviceFetchUTXOsFailed(serviceError))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,18 +250,15 @@ extension LightWalletGRPCService: LightWalletService {
|
||||||
),
|
),
|
||||||
callOptions: Self.callOptions(timeLimit: self.streamingCallTimeout)
|
callOptions: Self.callOptions(timeLimit: self.streamingCallTimeout)
|
||||||
)
|
)
|
||||||
|
var iterator = stream.makeAsyncIterator()
|
||||||
|
|
||||||
return AsyncThrowingStream { continuation in
|
return AsyncThrowingStream() {
|
||||||
Task {
|
do {
|
||||||
do {
|
guard let compactBlock = try await iterator.next() else { return nil }
|
||||||
for try await compactBlock in stream {
|
return ZcashCompactBlock(compactBlock: compactBlock)
|
||||||
continuation.yield(ZcashCompactBlock(compactBlock: compactBlock))
|
} catch {
|
||||||
}
|
let serviceError = error.mapToServiceError()
|
||||||
continuation.finish()
|
throw ZcashError.serviceBlockStreamFailed(serviceError)
|
||||||
} catch {
|
|
||||||
let serviceError = error.mapToServiceError()
|
|
||||||
continuation.finish(throwing: ZcashError.serviceBlockStreamFailed(serviceError))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue