This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
740f880
commit bb81e4f
Showing
6 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// AsyncBlockConsumerOperation.swift | ||
// OperationPlus | ||
// | ||
// Created by Matt Massicotte on 2020-03-23. | ||
// Copyright © 2020 Chime Systems Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// An asynchronous variant of BlockConsumerOperation | ||
public class AsyncBlockConsumerOperation<Input>: AsyncConsumerOperation<Input> { | ||
public typealias CompletionHandler = (Input, @escaping () -> Void) -> Void | ||
|
||
private let block: CompletionHandler | ||
|
||
public init(producerOp: ProducerOperation<Input>, block: @escaping CompletionHandler) { | ||
self.block = block | ||
|
||
super.init(producerOp: producerOp) | ||
} | ||
|
||
override open func main(with producedValue: Input) { | ||
block(producedValue, { | ||
self.finish() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// BlockConsumerOperation.swift | ||
// OperationPlus | ||
// | ||
// Created by Matt Massicotte on 2020-03-23. | ||
// Copyright © 2020 Chime Systems Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A block-based version of ConsumerOperation | ||
public class BlockConsumerOperation<Input>: ConsumerOperation<Input> { | ||
private let block: (Input) -> Void | ||
|
||
public init(producerOp: ProducerOperation<Input>, block: @escaping (Input) -> Void) { | ||
self.block = block | ||
|
||
super.init(producerOp: producerOp) | ||
} | ||
|
||
override open func main(with producedValue: Input) { | ||
block(producedValue) | ||
|
||
self.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters