Giter VIP home page Giter VIP logo

Comments (9)

gchudnov avatar gchudnov commented on May 18, 2024

Do you recommend using the chaining API? Are there any difference?

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

The chaining API is somewhat safer indeed, since you can call
WebKit().load(url1).wait('idle').png(file1).load(url2).wait('idle').png(file2)
rightaway and do not worry about details.
OR you can insert an error handler in between:

WebKit().load(url1).wait('idle').png(file1, function(err) {
  // err is any error that happened from implicit init() to load, wait, png
}).load(url2).wait('idle').png(file2, function(err) {
  // err is any error that happened from latest load, wait, png
})

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

Reproducing here the code given in #26

gchidnov
In the following code that uses the async to print images one after the other, the second load callback (marked as '---> LOAD-COMPLETE') is never called:

    var arr = [
      "https://www.mezilla.org/en-US/",
      "https://www.google.com"
    ];
    async.eachSeries(arr, function(it, cb) {
      var href = it;
      var filePath = path.resolve(__dirname, './shots/outN.png');
      console.error('---> LOAD', href);
      w.load(href, {}, function(err) {
        console.error('---> LOAD-COMPLETE');
        if(err) {
          console.error('---> LOAD-ERR', err);
          cb();
        } else {
          console.error('---> SETTING-IDLE');
          w.once('idle', function() {
            w.png(filePath, function(err) {
              console.error('---> PNG', href, err);
              cb();
            });
          });
        }
      });
    }, function(err) {
      done(err);
    });

Not sure what is the problem?

A complete test might something like this:

var WebKit = require('../');
var expect = require('expect.js');
var fs = require('fs');
var path = require('path');
var async = require('async');

describe.only("ordered png render calls", function suite() {
  this.timeout(20000);
  var w;
  before(function(cb) {
    var inst = new WebKit();
    inst.init({}, function(err) {
      if (err) return cb(err);
      w = inst;
      cb();
    });
  });
  it("should not stall", function(done) {
    var arr = [
      "https://www.mezilla.org/en-US/",
      "https://www.google.com/",
      "https://www.debian.org/"
    ];
    async.eachSeries(arr, function(it, cb) {
      var href = it;
      var filePath = path.resolve(__dirname, './shots/outN.png');
      console.error('---> LOAD', href);
      w.load(href, {}, function(err) {
        console.error('---> LOAD-COMPLETE');  // <--- callback not called for the second time
        if(err) {
          console.error('---> LOAD-ERR', err);
          cb();
        } else {
          console.error('---> SETTING-IDLE');
          w.once('idle', function() {
            w.png(filePath, function(err) {
              console.error('---> PNG', href, err);
              cb();
            });
          });
        }
      });
    }, function(err) {
      done(err);
    });
  });
});

And the same problem reproduced in case of 404:
e.g.

    var arr = [
      "http://www.google.com/asdsad"
      "https://www.google.com/"
    ];

from node-webkitgtk.

gchudnov avatar gchudnov commented on May 18, 2024

Right, it looks the load callback function is never called after the first failure.

No matter what type of API is used:

  it('should not stall', function(done) {
    var filePath = path.resolve(__dirname, './shots/outX.png');
    WebKit().load("http://www.google.com/asdsad").wait('idle').png(filePath, function(err) {
      //
    }).load("https://www.google.com/").wait('idle').png(filePath, function(err) {
      done(); // <---- never hits this line
    });
  });

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

Simplifying further,

W().load('http://mezilla.fr', function(err) {console.error(err);}).load('http://www.google.com', function(err) {console.error(err);})

second callback is not called, because there was a failure and that stopped the chain.
This is a behavior of chainit, not something specific here, so we must be careful about which API is used.

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

but

var W = require('./')
var inst = new W();
inst.init({}, function(err) {
  inst.load('http://mozilla.org', {}, function(err) {
    console.error(err);
    inst.load('http://mozilla.org', {}, function(err) {console.error(err)})
  });
});

does not call second callback either.

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

Ok, i'm NULL-ing the loadCallback in the c++ code at a moment it could have been set by a new Load call.

from node-webkitgtk.

kapouer avatar kapouer commented on May 18, 2024

Fixed by c888b54, and published a new version.

Note that it doesn't change the fact that

W().load('http://fsgdfgdfgdfgdferrpr.com', console.error).load('http://localhost', console.log.bind('ok'))

does not call the second load.

from node-webkitgtk.

gchudnov avatar gchudnov commented on May 18, 2024

got it, thank you!

from node-webkitgtk.

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.