Latest 1.2.1
Homepage https://github.com/e-sites/Bismuth
License MIT
Platforms ios 9.0, requires ARC
Frameworks Foundation
Authors

Bismuth

Bismuth is part of the E-sites iOS Suite.


A lightweight framework to handle queues

forthebadge forthebadge

Platform
CocoaPods Compatible
Carthage compatible
Travis-ci

Installation

Podfile:

pod 'Bismuth'

And then

pod install

Implementation

import Bismuth

struct AmazonSNSQueueItem: BismuthQueueable {
    enum CodingKeys: String, CodingKey {
        case type
        case topic
        case uuid
    }

    enum QueueType: String, Codable {
        case subscribe
        case unsubscribe
    }

    private var uuid = UUID().uuidString

    let type: QueueType
    let topic: String

    init(topic: String, type: QueueType) {
        self.topic = topic
        self.type = type
     }

    static func == (lhs: AmazonSNS.Queue.Item, rhs: AmazonSNS.Queue.Item) -> Bool {
        return lhs.uuid == rhs.uuid
    }
}
func configure() {
    var config = Bismuth.Config(identifier: "amazon-sns")
    config.logProxy = { line in
        print("[SNS] (line)")
    }
    config.autoStart = false // Default: true
    config.canRunInBackground = false // Default: true
    config.retryTime = 30 // Default: 15

    queue = Bismuth.Queue<AmazonSNSQueueItem>(config: config)
    queue.delegate = self
    queue.add(AmazonSNSQueueItem(topic: "topic-1", type: .subscribe))
    queue.add(AmazonSNSQueueItem(topic: "topic-2", type: .subscribe))
    queue.add(AmazonSNSQueueItem(topic: "topic-3", type: .subscribe))
    queue.add(AmazonSNSQueueItem(topic: "topic-4", type: .subscribe))
}

// BismuthQueueDelegate functions

func queue<T>(_ queue: Bismuth.Queue<T>, handle item: T, completion: @escaping (Bismuth.HandleResult) -> Void) where T : BismuthQueueable {
    guard let item = item as? AmazonSNSQueueItem else {
        completion(.handled)
        return
    }

    // Do stuff with the queue item
    doStuff { error in 
        if error == nil {
            completion(.handled)
        } else {
            completion(.retry)
       }        
    }
}

func queueFinished<T>(_ queue: Bismuth.Queue<T>) where T : BismuthQueueable {

}

Configuration

Key Type Description Default
autoStart Bool Do you want the queue to auto start upon app activation? true
reryTimeInterval TimeInterval Failed queue items will retry after x seconds 15
canRunInBackground Bool Can the queue operate in the background true
logProxy (String) -> Void A closure to call for debug logging nil

Control

Pause a queue until resume() is called

func pause()

Resumes a queue that was paused using pause()

func resume()

Starts a queue, that is idle

func start()

The current state of the queue (idle, paused or running)

var state: Bismuth.QueueState

Latest podspec

{
    "name": "Bismuth",
    "version": "1.2.1",
    "platforms": {
        "ios": "9.0"
    },
    "summary": "Queue handling",
    "authors": {
        "Bas van Kuijck": "[email protected]"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/e-sites/Bismuth",
    "source": {
        "git": "https://github.com/e-sites/Bismuth.git",
        "tag": "1.2.1"
    },
    "source_files": "Bismuth/**/*.{h,swift}",
    "requires_arc": true,
    "swift_version": "4.2",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This