forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlockfile.ts
More file actions
46 lines (40 loc) · 1.03 KB
/
Copy pathlockfile.ts
File metadata and controls
46 lines (40 loc) · 1.03 KB
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
///<reference path=".d.ts"/>
"use strict";
import Future = require("fibers/future");
import lockfile = require("lockfile");
import * as path from "path";
export class LockFile implements ILockFile {
private lockFilePath: string;
constructor(private $options: IOptions) {
this.lockFilePath = path.join(this.$options.profileDir, ".lock");
}
private static LOCK_EXPIRY_PERIOD_SEC = 180;
private static LOCK_PARAMS = {
retryWait: 100,
retries: LockFile.LOCK_EXPIRY_PERIOD_SEC*10,
stale: LockFile.LOCK_EXPIRY_PERIOD_SEC*1000
};
public lock(): IFuture<void> {
let future = new Future<void>();
lockfile.lock(this.lockFilePath, LockFile.LOCK_PARAMS, (err: Error) => {
if(err) {
future.throw(err);
} else {
future.return();
}
});
return future;
}
public unlock(): IFuture<void> {
let future = new Future<void>();
lockfile.unlock(this.lockFilePath, (err: Error) => {
if(err) {
future.throw(err);
} else {
future.return();
}
});
return future;
}
}
$injector.register("lockfile", LockFile);