GithubHelp home page GithubHelp logo

ankitthakur / dispatch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jarmourato/dispatch

0.0 2.0 0.0 14 KB

Just a tiny library to make using GCD easier and intuitive

License: MIT License

Ruby 8.50% Swift 91.50%

dispatch's Introduction

Dispatch

Swift 2.2 Platforms

Podspec License

codebeat badge

Installation

CocoaPods

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

pod 'Dispatch'

And then simply

import DispatchFramework

And your good to go!

Manually

  1. Download and drop Dispatch.swift anywhere you like in your project.
  2. That's it.

Usage

Basic

Dispatch.async(dispatch_get_main_queue()) {
  //Code to be run on the main thread
}
Or using the helpers provided by Dispatch.Queue enum
Dispatch.async(Queue.main) {
  //Code to be run on the main thread
}
Or using the overloaded method to run on the main thread
Dispatch.async {
  //Code to be run on the main thread
}

Types of Dispatch

Async

Dispatch.async(Queue.main) {
  //Code to be run on the main thread
}

Sync

let someCustomQueue = dispatch_queue_create("custom.queue.dispatch", DISPATCH_QUEUE_CONCURRENT)
Dispatch.sync(someCustomQueue) {
  //Code to be synchronously on someCustomQueue
}

After

Dispatch.after(1.0, queue: Queue.main) {
  //Code to be run on the main thread after 1 second
}
Or using the overloaded method to run on the main thread
Dispatch.after(1.0) {
  //Code to be run on the main thread after 1 second
}

Once

let token : dispatch_once_t
Dispatch.once(&token) {
  //Code to be run only once in App lifetime
}

Queue Helpers

Main queue

let mainQueue = Queue.main 

Custom queue

let customConcurrentQueue = Queue.custom("custom.concurrent.queue.dispatch", Queue.Atribute.concurrent)
let customSerialQueue = Queue.custom("custom.serial.queue.dispatch", Queue.Atribute.serial)

Global queues

let priority = 0 // or you use one of the Global priorities (ex: Queue.Priority.UserInteractive)
let globalQueue = Queue.global(priority)

// For comodity there are helpers for getting the Global queues

let globalUserInteractiveQueue = Queue.globalUserInteractive
let globalUserInitiatedQueue = Queue.globalUserInitiated
let globalUtilityQueue = Queue.globalUtility
let globalBackgroundQueue = Queue.globalBackground

Author

João Mourato, [email protected]

License

Dispatch is available under the MIT license. See the LICENSE file for more info.

dispatch's People

Contributors

gabrielpeart avatar jarmourato avatar

Watchers

 avatar  avatar

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.