3

i'm working with fabricJS and it's callback based library to parse canvas <--> svg and i'm stuck in the following senario.

function A () {
   ...
   B(svgString)
   ...
}

function B (svgString) {
   ...
   fabric.loadSVGFromString(svgString, function(objects, options){
      ...
      canvas.add(..);
      canvas.renderAll();
   });
   ...
}

When using this with a simple svg file it workes fine, but when loading an svg with an embedded base64 png it jumps to the next instruction in function A without completing the callback in function B

Ilyas Ghomrani
  • 408
  • 6
  • 26
  • While the duplicate is nominally about returning a value, the issue it really covers is finishing an asynchronous function before continuing from the calling function (because that is a prerequisite for returning a value from the asynchronous function). – Quentin May 26 '21 at 09:19
  • 1
    The principles in the linked solution still apply, although I don't really agree with this issue being closed since in the context of Fabric.js this is a common question. The solution is to have function A pass a callback to function B that gets called when function b completes. – melchiar May 29 '21 at 01:20

0 Answers0