Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/littlstar/lsbatch
Batch control flow for Objective-C
https://github.com/littlstar/lsbatch
Last synced: about 2 months ago
JSON representation
Batch control flow for Objective-C
- Host: GitHub
- URL: https://github.com/littlstar/lsbatch
- Owner: littlstar
- License: mit
- Created: 2015-09-09T16:49:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-24T01:43:15.000Z (over 9 years ago)
- Last Synced: 2024-10-31T16:18:16.964Z (3 months ago)
- Language: Objective-C
- Size: 172 KB
- Stars: 1
- Watchers: 23
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LSBatch
LSBatch control flow for Objective-C
## Installation
LSBatch is available through [CocoaPods](http://cocoapods.org/). To install it,
simply add the following line to your `Podfile`:```ruby
pod "LSBatch"
```LSBatch is also available through [clibs](https://github.com/clibs/clib).
To install it, simply run:```sh
$ clib install littlstar/LSBatch
```or add it to your `package.json` file:
```json
...
"dependencies": {
"littlstar/LSBatch": "*"
}
...
```## Usage
LSBatch provides mechanisms for adding block control flow and invoking
them with a set concurrency. LSBatch supports a delegate pattern as well.Using LSBatch is as simple as providing a block for work to be done. The
block is a type defined with the following `typedef`:```objc
typedef void (^LSBatchWorkerCallback)(LSBatchNextCallback);
```Where `LSBatchNextCallback` is the callback block that should be called
when work is complete for the "worker block". It is a type defined with
the following `typedef`:```objc
typedef void (^LSBatchNextCallback)(id err);
```You can provide a callback block that is executed when all work is
complete. The block is a type defined with the following `typedef`:```objc
typedef void (^LSBatchDoneCallback)(id err);
```A simple worker example can constructed as such:
```objc
LSBatch *batch = [LSBatch new: INFINITY];// queue work
[batch push: ^(LSBatchNextCallback next) {
// do work here
next(nil);
}];// more work
[batch push: ^(LSBatchNextCallback next) {
// more work here
next(nil);
}];// Execute worker blocks calling the provided
// callback block.
[batch end: ^(NSError *err) {
if (err) {
// handle error
} else {
// handle success
}
}];
```### Delegates
LSBatch defines the following `LSBatchDelegate` protocol:
```objc
@protocol LSBatchDelegate// Called when batch did finish all work.
- (void) batchDidFinish: (id ) batch;// Called when batch encountered an error.
- (void) batch: (id ) batch didFailWithError: (id ) err;// Called when batch work has been aborted.
- (void) batchDidAbort: (id ) batch;
@end
```## Documentation
Coming soon...
## License
MIT