Uh oh!
There was an error while loading. Please reload this page.
forked from jspm/github
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec-git.js
More file actions
Latest commit
77 lines (72 loc) · 1.91 KB
/
Copy pathexec-git.js
File metadata and controls
77 lines (72 loc) · 1.91 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
constexec=require('child_process').exec;
constos=require('os');
classPool{
constructor(count){
this.count=count;
this.queue=[];
this.promises=newArray(count);
}
}
/* Run the function immediately. */
functionrun(pool,idx,executionFunction){
varp=Promise.resolve()
.then(executionFunction)
.then(()=>{
deletepool.promises[idx];
varnext=pool.queue.pop();
if(next)
pool.execute(next);
});
pool.promises[idx]=p;
returnp;
}
/* Defer function to run once all running and queued functions have run. */
functionenqueue(pool,executeFunction){
returnnewPromise(resolve=>{
pool.queue.push(()=>{
returnPromise.resolve()
.then(executeFunction)
.then(resolve);
});
});
}
/* Take a function to execute within pool, and return promise delivering the functions
* result immediately once it is run. */
Pool.prototype.execute=function(executionFunction){
varidx=-1;
for(vari=0;i<this.count;i++)
if(!this.promises[i])
idx=i;
if(idx!==-1)
returnrun(this,idx,executionFunction);
else
returnenqueue(this,executionFunction);
};
if(process.platform==='win32'){
vargitPool=newPool(Math.min(os.cpus().length,2));
module.exports=function(command,execOpt){
returnnewPromise((topResolve,topReject)=>{
returngitPool.execute(function(){
returnnewPromise(resolve=>{
exec('git '+command,execOpt,(err,stdout,stderr)=>{
if(err)
topReject(stderr||err);
else
topResolve(stdout);
resolve();
});
});
});
});
};
}
else{
module.exports=(command,execOpt)=>newPromise((resolve,reject)=>{
exec('git '+command,execOpt,(err,stdout,stderr)=>{
if(err)
reject(stderr||err);
else
resolve(stdout);
});
});
}