Code Monkey home page Code Monkey logo

bapersistentoperationqueue's Introduction

BAPersistentOperationQueue

A persistent operation queue that uses a database to save operations that need to be completed at a later time.

Build Status Coverage Status Pod Version Pod Platform Pod License

BAPersistentOperation employs a FIFO queue that uses both a database and an in-memory queue to save operations that, for some reason, must be completed at a later time. The best use case (and the purpose of its existence!) is to allow POST/PUT/DELETE requests in an app to be saved and performed in their correct order at a later time, in case the network connection is unavailable. It uses an NSOperationQueue to automatically handle these operations in separate threads, and makes use of delegate methods to provide the host application “hooks” to serialize and deserialize objects for greater flexibility.

Its only dependency is FMDB.

Example

To run the example project; clone the repo, and run pod install from the Example directory first. The project consists of a simple table view that allows you to create "Requests", which are mock asynchronous operations that have a random amount of latency before they finish. There is also a button to make your app go "online" and "offline". When "offline", any new requests added start in a "Stopped" state. When you either go "online" or restart the application, these Requests are inserted into a queue and then performed one at a time.

Requirements

FMDB

Installation

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

pod "BAPersistentOperationQueue"

How to use

Full documentation is available through CocoaDocs, but here are the highlights:

The queue

startWorking

Starts processing operations in the queue. If the queue has no operations in memory, it will try to load more from the database.

stopWorking

Stops processing operations in the queue.

loadOperationsFromDatabase

Loads operations from the database into the memory queue.

The BAPersistentOperationQueue Delegate

The class where you'll use the queue can (and probably should) conform to this protocol.

persistentOperationQueueSerializeObject:

This hook gives you the chance to serialize your custom objects into the queue. You should return an NSDictionary with arbitrary data that you want to save. This data will later be used to reconstruct your object.

persistentOperationQueueStartedOperation:

This hook is triggered when an operation begins processing. You are then able to use the operation's data property to reconstruct your original object. You are also responsible for finishing the operation in this delegate, by calling [operation finish].

License

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

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.