Coder Social home page Coder Social logo

albinzr / swiftytask Goto Github PK

View Code? Open in Web Editor NEW
22.0 1.0 1.0 19 KB

An extreme queuing system with high performance for managing all task in app with closure

License: MIT License

Ruby 14.08% Swift 79.79% Objective-C 6.14%
swift swifty dispatchqueue backgroundqueue

swiftytask's Introduction

SwiftyTask

An extreme queuing system with high performance for managing all task in app with closure

Task

Swift 3.0 Platforms iOS Xcode 8.0 Gemnasium Ratting license

Method Tasking of queued closure on GCD (Grand Central Dispatch).

Requirements

  • iOS 10.0+
  • Swift 4.1+
  • Xcode 9.2+

Installation

CocoaPods

Task is available through CocoaPods. To install it, simply add the following line to your Podfile:

use_frameworks!

pod "SwiftyTask"

or

use_frameworks!

pod 'SwiftyTask', git: 'https://github.com/Albinzr/SwiftyTask', :tag => '1.0.1'

Carthage

To integrate Task into your Xcode project using Carthage, specify it in your Cartfile:

github "CR-Creations/SwiftyTask"

Example

Basics

SwiftyTask.main {

    // main thread queue

    return "1"
    }.background { result in

         // background qos class thread queue
         print(result) 

         return "2"
    }.userInteractive { result in

         // userInteractive qos class thread queue
         print(result) 

         return "3"
    }.userInitiated { result in
         //userInitiated qos class thread queue
         print(result) 

         return "4"
    }.onDefault { result in
         // default qos class thread queue

         print(result)
         return "5"
    }.run(.Main) { result in

         // called at main thread queue
         print(result) 
         print("Process completion")
}

Custom queue

let queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)

SwiftyTask.custom(queue) {
    
    //customQueue

    return nil
    }.onDefault { result in

         //default qos class thread queue

         return result
    }.main { result in

         //main thread queue

         return result
    }.custom(customQueue) { result in
         
         // customQueue
         
         return result
    }.run()

After

SwiftyTask.main {
    
    // main thread queue

    print("start after: \(Date().description)")

    return "1"
    }.after(seconds: 5) { result in

        // 5 seconds after the previous block
        //background qos class thread queue

        print(result)
        return "after 2: \(Date().description)"
    }.userInteractive { result in

        //userInteractive qos class thread queue

        print(result)
        return "after 3: \(Date().description)"
    }.after(Queue.Utility, seconds: 5) { result in

        //5 seconds after the previous block
        // called at utility qos class thread queue

        print(result) 
        return "after 4: \(Date().description)"
    }.run(.Main) { result in

        // last call main thread queue

        print(result) 
        print("after completion: \(Date().description)")
}

Wait

SwiftyTask.main {

    //  main thread queue

    print("start wait: \(Date().description)")
    return "1"
    }.wait(seconds: 5).background { result in

        // 5 seconds after the previous block
        // background qos class thread queue

        print("wait 2: \(Date().description)")
        return result
    }.wait(seconds: 5).main { result in

        // 5 seconds after the previous block
        // main thread queue

        print("wait 3: \(Date().description)")
        return result
    }.run()

License

MIT license. See the LICENSE file for more info.

swiftytask's People

Contributors

albin-cr avatar albinzr avatar

Stargazers

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

Watchers

 avatar

Forkers

swiftstudioist

swiftytask's Issues

Example Project

I'd be cool to have an example project, showcasing the library

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.