This commit is contained in:
joshaber 2016-04-19 14:56:58 -04:00
Родитель 74204c6338
Коммит 27588138b9
7 изменённых файлов: 1223 добавлений и 12 удалений

Просмотреть файл

@ -1,5 +1 @@
import * as NodeGit from 'nodegit'
export default class Repository {
repository: NodeGit.Repository
}
export * from './repository'

1090
lib/repository.ts Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

60
lib/resource-pool.ts Normal file
Просмотреть файл

@ -0,0 +1,60 @@
export type WorkFunction<T, V> = (resource: T) => Promise<V>
// Manages a pool of some resource.
export default class ResourcePool<T> {
private pool: T[]
private queue: Array<(resource: T) => void>
public constructor(pool: T[]) {
this.pool = pool
this.queue = []
}
// Enqueue the given function. The function will be given an object from the
// pool. The function must return a {Promise}.
public enqueue<V>(fn: WorkFunction<T, V>): Promise<V> {
let resolve: (result: V) => void = null
let reject: (error: Error) => void = null
const wrapperPromise = new Promise<V>((resolve_, reject_) => {
resolve = resolve_
reject = reject_
})
this.queue.push(this.wrapFunction(fn, resolve, reject))
this.dequeueIfAble()
return wrapperPromise
}
private wrapFunction<V>(fn: WorkFunction<T, V>, resolve: (result: V) => void, reject: (error: Error) => void): (resource: T) => void {
return (resource) => {
const promise = fn(resource)
promise
.then(result => {
resolve(result)
this.taskDidComplete(resource)
}, error => {
reject(error)
this.taskDidComplete(resource)
})
}
}
private taskDidComplete (resource: T) {
this.pool.push(resource)
this.dequeueIfAble()
}
private dequeueIfAble () {
if (!this.pool.length || !this.queue.length) { return }
const fn = this.queue.shift()
const resource = this.pool.shift()
fn(resource)
}
public getQueueDepth () { return this.queue.length }
}

Просмотреть файл

@ -6,15 +6,20 @@
"typings": "./build/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "tsc"
"prepublish": "npm run lint && tsc",
"lint": "tslint lib/**/*.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"tslint": "^3.7.4",
"typescript": "^1.8.10",
"typings": "^0.7.12"
},
"dependencies": {
"nodegit": "^0.12.2"
"event-kit": "^2.0.0",
"fs-plus": "^2.8.2",
"nodegit": "^0.12.2",
"underscore-plus": "^1.6.6"
}
}

Просмотреть файл

@ -1,13 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"moduleResolution": "node",
"target": "es6",
"noImplicitAny": true,
"sourceMap": false,
"outDir": "build",
"outDir": "./build",
"declaration": true
},
"exclude": [
"node_modules"
"node_modules",
"build",
"typings/main",
"typings/main.d.ts"
]
}

56
tslint.json Normal file
Просмотреть файл

@ -0,0 +1,56 @@
{
"rules": {
"class-name": true,
"curly": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"no-duplicate-variable": true,
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace"
],
"quotemark": [
true,
"singe"
],
"semicolon": [
false,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-separator",
"check-type"
]
}
}

Просмотреть файл

@ -1,5 +1,5 @@
{
"ambientDependencies": {
"node-git": "registry:dt/node-git#0.0.0+20160316155526"
"node": "registry:dt/node#4.0.0+20160412142033"
}
}