thread-safe-block-queue 0.1.4

thread-safe-block-queue 0.1.4

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年7月

Shaheen Ghiassy维护。



示例

要运行示例项目,首先克隆存储库,然后在Example目录中运行pod install

安装

thread-safe-block-queue可以通过CocoaPods安装。要安装它,只需将其以下行添加到Podfile

pod "thread-safe-block-queue"

安装Pod

pod install

然后将以下内容添加到您的代码中

#import <thread-safe-block-queue/ThreadSafeBlockQueue.h>
ThreadSafeBlockQueue *queue = [[ThreadSafeBlockQueue alloc] init];

描述

Thread Safe Block Queue (TSBQ) 是我需要的一种特殊数据结构。类似于 NSOperation,它为运行块提供了一个FIFO队列。队列最初是挂起的,随后由开发人员恢复。

TSBQ除了提供 NSOperationQueue 的功能外,还提供了播放给 TSBQ 的块的能力。这个独特功能在我正在工作的项目中是必要的,并且由于其高度测试和线程安全,我将其公开。

//   ┌────────────────────────────────┐
//   │  Queue starts at HEAD with 0   │
//   └────────────────────────────────┘
//       │
//       │
//       │
//       │
//       │
//       │
//       ▼
//
//      null
//
//
//
//
//
//
//   ┌─────────────────────────────────────────────┐
//   │     Blocks come in and are queued FIFO      │
//   └─────────────────────────────────────────────┘
//       │
//       │
//       │
//       │
//       │
//       │
//       ▼
//  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
//  │         │ │         │ │         │ │         │ │         │
//  │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │
//  │         │ │         │ │         │ │         │ │         │
//  └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
//
//
//
//
//
//
//
//
//   ┌───────────────────────────────────────────────────────────────────────────────┐
//   │ Dequeuing the data structure causes the blocks to be run in sequential order  │
//   └───────────────────────────────────────────────────────────────────────────────┘
//                                                       │
//                                                       │
//                                                       │
//          ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ▶  │
//                                                       │
//                                                       │
//       ▼                                               ▼
//  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
//  │         │ │         │ │         │ │         │ │         │
//  │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │
//  │         │ │         │ │         │ │         │ │         │
//  └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
//
//
//
//
//
//
//
//
//
//
//                                        ┌──────────────────────────────────────────┐
//                                        │Subsequent blocks will be run immediately │
//                                        └──────────────────────────────────────────┘
//                                                                   │
//                                                                   │
//                                                        ─ ─ ─ ─ ─▶ │
//                                                                   │
//                                                                   │
//                                                                   │
//                                                       ▼           ▼
//  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
//  │         │ │         │ │         │ │         │ │         │ │         │
//  │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │
//  │         │ │         │ │         │ │         │ │         │ │         │
//  └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
//
//
//
//
//
//
//
//
//
//
//
//
//    ┌────────────────────────────────────────────────────────────┐
//    │  Hitting replay will cause the queue to be rerun in FIFO   │
//    └────────────────────────────────────────────────────────────┘
//
//       ╳                                                           │
//       ╳                                                           │
//       ╳  ─ ─ ─ ─ ─ ─ ─ ─ ─ ─replay ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─▶ │
//       ╳                                                           │
//       ╳                                                           │
//       ╳                                                           │
//       ▼                                                           ▼
//  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
//  │         │ │         │ │         │ │         │ │         │ │         │
//  │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │
//  │         │ │         │ │         │ │         │ │         │ │         │
//  └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
//
//
//
//
//
//
//
//
//
//
//
//
//
//   ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────┐
//   │    Should new blocks be added during replay mode they will simply be appended and run in FIFO order     │
//   └─────────────────────────────────────────────────────────────────────────────────────────────────────────┘
//
//                               ╳                                             │
//                               ╳                                             │
//                               ╳  ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─▶ │
//                               ╳                     replay                  │
//                               ╳                                             │
//                               ╳                                             │
//                               ▼                                             ▼
// ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
// │         │ │         │ │         │ │         │ │         │ │         │ │         │
// │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │ │  Block  │
// │         │ │         │ │         │ │         │ │         │ │         │ │         │
// └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘

作者

Shaheen Ghiassy, [email protected]

许可证

thread-safe-block-queue可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。