GithubHelp home page GithubHelp logo

quanvo87 / groupwork Goto Github PK

View Code? Open in Web Editor NEW
42.0 5.0 5.0 274 KB

Easy, concurrent, asynchronous tasks in Swift.

License: MIT License

Objective-C 10.67% Swift 69.82% Ruby 17.94% Makefile 1.57%
swift asynchronous dispatch concurrency dispatch-group

groupwork's Introduction

iOS Linux Swift CocoaPods Version Status CocoaPods CocoaPods Carthage compatible Build Status MIT License

GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way. This helps make large functions with multiple asynchronous tasks more clear and easy to follow.

Contents

  1. Requirements
  2. Installation
  3. Documentation
  4. Example Usage
  5. Working Example
  6. License
  7. Authors

Requirements

Swift 4

Installation

CocoaPods

For CocoaPods, add to Podfile:

pod 'GroupWork', '~> 0.0'

Carthage

For Carthage, add to Cartfile:

github "quanvo87/GroupWork"

Swift Package Manager

For SPM, add to your package dependencies:

.package(url: "https://github.com/quanvo87/GroupWork.git", .upToNextMinor(from: "0.0.0"))

Manually

  • for projects, drag GroupWork.swift to the project tree
  • for workspaces, include the whole GroupWork.xcodeproj

Documentation

Here

Example Usage

End Goal

import GroupWork

...

func complexFunc(completion: @escaping (Bool) -> Void) {
  let work = GroupWork()

  work.asyncFuncA()
  work.asyncFuncB()
  work.asyncFuncC()

  work.allDone() {
    completion(work.result)
  }
}

...

complexFunc is a function that returns the result of three asynchronous functions asyncFuncA(), asyncFuncB(), and asyncFuncC(), running concurrently. The completion handler is called only when all these functions have completed. Usage of this library has enabled the above clean interface. This can be scaled to much higher than three asynchronous functions.

notes:

  • the asynchronous functions should be able to run concurrently without affecting each other
  • work.result is only a simple Bool
  • this is not an answer to callback hell

Set Up

There is some set up required in order to create complexFunc() from above:

import GroupWork

extension GroupWork {
  func asyncFuncA() {
    start()
    networkCallA() { (result) in
      self.finish(withResult: result)
    }
  }

  func asyncFuncB() {
    start()
    networkCallB() { (result) in
      self.finish(withResult: result)
    }
  }

  func asyncFuncC() {
    start()
    networkCallC() { (result) in
      self.finish(withResult: result)
    }
  }
}

Now you can create a GroupWork, and call work.simpleFuncA() on it like in the example.

notes:

  • start() must be called before an asynchronous task
  • finish() must be called in the completion handler of an asynchronous task
  • start() and finish() calls must be balanced

Working Example

The tests have a working example.

License

MIT LICENSE

Authors

Please provide attribution, it is greatly appreciated.

groupwork's People

Contributors

dingwilson avatar quanvo87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

groupwork's Issues

SPM

I could see this being used by frameworks as well.

What do we have to do for that?

Linux support

i think it already supports linux but we should set up a linux build on travis

do

Things to Consider Before Release:

  • Branding
    • Creating longer description optimized w/ keywords for search. (We already have the short summary, but need a longer description for README introduction and podspec).
    • Maybe some sort of small logo/header image for README? Maybe just a stylized "GroupWork" image. Images > Text.
  • README
    • Badges for a "quick glance" for Swift 4 support, latest pod version, travis build status (if we decide to test), etc.
    • Fix Link to Docs
    • Add instructions to install via CocoaPods/Carthage/Manual
  • Implementing some of GitHub's special md files
    • Changelog
    • Issue/PR Templates
    • etc..
  • Generate Jazzy Docs
  • Maybe an example project using GroupWork

Things to Consider After Release:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.