2016-10-11 2 views
0

Использование nodegit, как мне отменить длительную операцию клонирования? Наше репо похоже на 3 ГБ, пользователь может отказаться от него, потому что он занимает слишком много времени.Как отменить операцию клонирования 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)

Если вы не хотите, чтобы создать совершенно новый файл модуль, вы можете использовать НУЮ 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 
 
       } 
 
      } 
 
     });