JavaScript 任务队列简单实现

基本代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function FQKTask(params) { this.params = params; }
FQKTask.prototype = {func: undefined};

function FQKTaskQueue() {
this._pendingTasks = [];
this._runningTasks = [];
}
FQKTaskQueue.prototype = {
_maxOperationCount: 1,
_pendingTasks: undefined,
_runningTasks: undefined,
isFunction: function (functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
},
setMaxOperationCount: function (count) {
if(count > 0)
{
this._maxOperationCount = Number(count);
}
},
addTask: function (task) {
if(!(task instanceof FQKTask))
{
return ;
}

if(!this.isFunction(task.func))
{
throw new Error('You must define task\'s func');
}

if(this._runningTasks.length < this._maxOperationCount)
{
this._runningTasks.push(task);
task.func(task);
}
else
{
this._pendingTasks.push(task);
}
},
removeTask: function (task) {
if(!(task instanceof FQKTask))
{
return ;
}

var index = this._runningTasks.indexOf(task);
if (index >= 0) {
this._runningTasks.splice(index, 1);
}

if(this._pendingTasks.length > 0)
{
var pendingTask = this._pendingTasks[0];
this._pendingTasks.splice(0, 1);
this.addTask(pendingTask);
}
}
};

Nginx - extensionless-php

参考链接

Nginx PHP 7 - curl_init

参考链接

HTTPS - Let's Encrypt

参考链接

PHP 手册

MySQL - 复制表

参考链接

CocoaPods 头文件引用自动补全

Build Settings -> Search Paths -> User Header Search Paths,添加 $(PODS_ROOT),并设定为 recursive

TitleView iOS 11 适配

参考链接

NSAttributedString 删除线的问题

cloc - 统计代码行数

1
2
3
4
5
6
## 安装
brew install cloc

## 使用
cd SOME_DIR
cloc .