Giter VIP home page Giter VIP logo

Comments (6)

jo avatar jo commented on July 17, 2024

Hi @broerse, welcome to nodejs!

You can use async, which

provides straight-forward, powerful functions for working with asynchronous JavaScript.

With async.each() (to handle the upload in paralell) or async.eachSeries() (to push one file after the other) callback is called when all files have been processed:

- distFiles.forEach(function (item) {
+ async.eachSeries(distFiles, function (item) {
//
+}, callback)

from couchdb-push.

broerse avatar broerse commented on July 17, 2024

Thanks but the problem seems to be that push is stopped because the script ends. Just tried RSVP but it does not help yet. It also does not wait?

      upload: function(/* context */) {
        var couchDir    = this.readConfig('couchDir');
        var db          = this.readConfig('db');
        var promise = new Promise(function(resolve, reject) {
          push(db, couchDir, function(error, response) {
            if(error) {
              reject(response);
            } else {
              resolve('Upload OK');
            }
          });
        });
        promise.then(function(value) {
          // on fulfillment
          console.log(value);
        }, function(reason) {
          // on rejection
          console.log(value);
        });
        console.log('zzzz');
      },

from couchdb-push.

jo avatar jo commented on July 17, 2024

Have you tried to return the promise from the upload function?

from couchdb-push.

broerse avatar broerse commented on July 17, 2024

Yes I see the distFiles.forEach is wrong. Thanks. I will test if it is the problem I have.

from couchdb-push.

jo avatar jo commented on July 17, 2024

No, I think I was wrong - I overread that didBuild is sync because you used writeFileSync. You maybe need to return a Promise from the upload function like you wrote in the comment above.

from couchdb-push.

broerse avatar broerse commented on July 17, 2024

That was it:

      upload: function(/* context */) {
        var couchDir    = this.readConfig('couchDir');
        var db          = this.readConfig('db');
        var promise = new Promise(function(resolve, reject) {
          push(db, couchDir, function(error, response) {
            if(error) {
              console.log('Error');
              reject(response);
            } else {
              console.log('Upload OK');
              resolve('Upload OK');
            }
          });
        });
        console.log('Start Upload');
        return promise;
      },

Many Thanks!!!

Just deployed: https://martinic.cloudant.com/emberapp/_design/deploytest1/_rewrite/

from couchdb-push.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.