Git Product home page Git Product logo

raschedulingkit's Introduction

RASchedulingKit

Callback-based NSOperation subclasses. Asynchronous programming made easy. Spliced from IRFoundations.

Using RASchedulingKit

The Scheduling Kit gives you an Async Operation, a Suspension-Counted Operation Queue, and a RAScheduling Category on NSObject.

Async Operation

The Async operation is the crux of the kit. You can easily wrap a long-running piece of code in an NSBlockOperation and queue it, passing the value out of the scope later on. However, this does not work for things that already provide asynchronous callbacks. You would have to wait for the callbacks to come in. Or you can react to the callbacks.

In which case, use +[RAAsyncBarrierOperation operationWithWorker:callback:]:

RAAsyncBarrierOperation *operation = [RAAsyncBarrierOperation operationWithWorker:^(RAAsyncOperationCallback callback) {

	[AFSomething doSomethingWithCompletion:^(BOOL didFinish, id results, NSError *error){
	
		if (didFinish) {
		
			callback(results);
		
		} else {

			callback(error);
		
		}
	
	}];
	
} callback: ^ (id results) {

	//	Process the results
	
}];

The operation will keep itself on the queue and wait until the callback block is called to mark itself finished. Dependencies still work.

In cases you want to do work on different threads, use +operationWithWorker:trampoline:callback:trampoline:. The worker and callback trampolines allow, and trust you to invoke the block elsewhere on their behalf.

Suspension-Counted Operation Queue

There is a RAOperationQueue which provides -beginSuspendingOperations and -endSuspendingOperations. It does not allow calls into -setSuspended: directly but manages the suspension state for you.

This is usually not useful until you have operations that would trigger UI updates, for example a table view reload or animated update, that should really not happen in the middle of an user interaction.

RAScheduling Category on NSObject

NSObject+RAScheduling.h introduces these methods on NSObject:

  • -ra_performBlock:, which enqueues a block wrapped in an async operation, with block trampolines to the main queue.
  • -ra_cancelBlocks, which cancels every update.

raschedulingkit's People

Contributors

evadne avatar

Stargazers

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

Watchers

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