Giter VIP home page Giter VIP logo

async.legacy.oc's Introduction

Async.legacy.OC

Rewrite Async.legacy by Objective-C (iOS7+ and OS X 10.9+ compatible)

Async sugar looks like this:

Async.background(^{
    NSLog(@"A: This is run on the background");
}).main(^{
    NSLog(@"B: This is run on the , after the previous block");
});

Instead of the familiar syntax for GCD:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    NSLog(@"A: This is run on the background");

    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"B: This is run on the , after the previous block");
    });
});

Things you can do

Supports the modern queue classes:

Async.main (^{})
Async.userInteractive (^{})
Async.userInitiated (^{})
Async.utility (^{})
Async.background (^{})

Chain as many blocks as you want:

Async.userInitiated (^{
    // 1
}).main (^{
    // 2
}).background (^{
    // 3
}).main (^{
    // 4
})

Instend of `dispatch_after

// After
CGFloat seconds = .5;
NSLog(@"---------------");
Async.after(seconds).main(^{
    NSLog(@"Is called after 0.5 seconds");
}).after(.4).background(^{
    NSLog(@"At least 0.4 seconds after previous block, and 0.5 after Async code is called");
});

Cancel blocks

// Cancel blocks not yet dispatched
AsyncBlock block1 = Async.background(^{
    // Heavy work
    for (NSUInteger i=0; i < 1000; i++) {
        NSLog(@"A %zd",i);
    }
});
AsyncBlock block2 = block1.background(^{
    NSLog(@"B - shouldn't be reached, since cancelled");
});
Async.main(^{
    [block1 cancel];
    [block2 cancel];
});

async.legacy.oc's People

Contributors

nsoio avatar

Watchers

 avatar  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.