GithubHelp home page GithubHelp logo

linkedin / cassette Goto Github PK

View Code? Open in Web Editor NEW
95.0 44.0 17.0 455 KB

An efficient, file-based FIFO Queue for iOS and macOS.

License: BSD 2-Clause "Simplified" License

Objective-C 96.52% Ruby 0.77% C 0.70% Swift 1.56% Shell 0.43%

cassette's Introduction

Build Status

Cassette

Cassette is a collection of queue-related classes for iOS and macOS. It is maintained by LinkedIn. Cassette was originally implemented by Segment. Cassette was inspired by Tape.

QueueFile is an efficient, file-based FIFO queue. Addition and removal from an instance is an O(1) operation. Writes are synchronous; data will be written to disk before an operation returns. The queue is intended to be reliable and survive system or process crashes.

Installing the Library

CocoaPods

target 'MyApp' do
  pod 'Cassette', '1.0.0-beta3'
end

Manual

Download the latest binary of the library.

Usage

CASObjectQueue works with arbitrary objects that abide by the NSCoding protocol. An CASObjectQueue may be backed by a persistent CASQueueFile, or in memory.

CASObjectQueue<NSNumber *> *queue;

// Persistent ObjectQueue
NSError *error;
queue = [[CASFileObjectQueue alloc] initWithRelativePath:@"Test-File" error:&error];

// In-Memory ObjectQueue
queue = [[CASInMemoryObjectQueue alloc] init];

Add some data to the end of the queue.

NSError *error;
if ([queue add:@1 error:&error]) {
  // Success
} else {
  NSLog(@"Error: %@", error);
}

Read data at the head of the queue.

// Peek the eldest element. Note that -peek:error: on an empty queue
// returns @[], but on error (e.g., I/O error) it returns nil.
NSNumber *data = [queue peek:1 error:&error].firstObject;

// Peek the eldest `n` elements.
NSArray<NSNumber *> *data = [queue peek:n error:&error];

Remove processed elements.

// Remove the eldest element.
if ([queue pop:1 error:&error]) { ... }

// Remove 'n' elements.
if ([queue pop:n error:&error]) { ... }

// Remove all elements.
if ([queue clearAndReturnError:&error]) { ... }

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.