Code Monkey home page Code Monkey logo

spasync's Introduction

SPAsync

by Joachim Bengtsson [email protected]

Tools for abstracting asynchrony in Objective-C. Read the introductory blog entry for much more detail.

SPTask

System.Threading.Tasks.Task in .Net is very nice. It's a standard library class representing any asynchronous operation that yields a single value. This is deceivingly simple, and gives you much more power of abstraction than you would initially believe.

SPTask is a minimal copy of .Net Task in Objective-C, with functionality to chain multiple asynchronous operations. You can think of it as an extremely lightweight ReactiveCocoa.

SPAgent

An experimental multithreading primitive. The goal is to make every "manager" style class multithreaded with its own work queue, and then make communication between these agents trivial.

SPAwait

Experimental copy of C# 5's "await" keyword, using the preprocessor.

- (SPTask<NSNumber> *)uploadThing:(NSData*)thing
{
    // Variables you want to use need to be declared as __block at the top of the method.
    __block NSData *encrypted, *confirmation;
    
    SPAsyncMethodBegin // Start of an async method, similar to 'async' keyword in C#
    
    // Do work like normal
    [self prepareFor:thing];
    
    // When you make a call to something returning an SPTask, you can wait for its value. The method
    // will actually return at this point, and resume on the next line when the encrypted value is available.
    encrypted = SPAsyncAwait([_encryptor encrypt:thing]);
    
    [_network send:encrypted];
    
    confirmation = SPAsyncAwait([_network read:1]);
    
    // Returning will complete the SPTask, sending this value to all the callbacks registered with it
    return @([confirmation bytes][0] == 0);
    
    SPAsyncMethodEnd
}

Extensions

In the Extensions folder you'll find extensions to other libraries, making them compatible with SPTask in various ways. You'll have to compile these in on your own when you need them; otherwise they would become dependencies for this library.

spasync's People

Contributors

nevyn avatar bgerstle avatar wader avatar tancred avatar

Watchers

Patrik Sjöberg avatar James Cloos 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.