2016-10-11 14 views
0

nodegitを使用すると、長時間実行されているクローン操作をどのように取り消すことができますか?私たちのレポは3GBのようなもので、あまりにも多くの時間を費やしているため、ユーザーは中止したいかもしれません。nodegitクローン操作をキャンセルするにはどうすればよいですか?

私は約束を拒否できますか?そのようです?

var cloneRepository = NodeGit.Clone(cloneURL, localPath, cloneOptions); 
... 
if (abortCondition) 
    cloneRepository.reject(); 

答えて

0

答えはa post on gitter.imでした。

基本的に、私たちは約束を拒否できません。 child_process.fork()を使用して子プロセスを生成し、それを強制終了してクローンを中止する必要があります。

const fork = require('child_process').fork; 
var childProcess = fork("clone.js", null, { silent: true}); 

... 
childProcess.kill(); 
0

(dstjへの追加)

あなたは完全に新しいモジュールファイルを作成したくない場合は、NPMのforkmeを使用することができます。

// Import for this process 
 
var path = require("path"); 
 
    
 
var child = forkme([{ 
 
      param1, 
 
      param2, 
 
      param3, 
 
      param4,//\ 
 
      param5 // \ 
 
     }],  // -> These can't be functions. Only static variables are allowed. 
 
      function (outer) { 
 
       // This is running in a separate process, so modules have to be included again 
 
       
 
       // Note that I couldn't get electron-settings to import here, not sure if that can be replicated on a fresh project. 
 
       var path = require("path"); 
 
       
 
       // Variables can be accessed via 
 
       console.log(outer.param1) 
 
       
 
       process.send({ foo: "bar" }); 
 
       
 
       process.exit(-1); // Returns -1 
 
        }); 
 

 
     child.on('message', (data) => { 
 
      console.log(data.foo); 
 
     }); 
 

 
     child.on('exit', (code) => { 
 
      if (code !== null) { // Process wasnt killed 
 
       if (code == 0) { // Process worked fine 
 
        // do something 
 
       } else { // Some error happened 
 
        var err = new Error("crap."); 
 
        // do something 
 
       } 
 
      } 
 
     });

関連する問題