SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

document save callback didn't execute right after document actually changed

Open funfungo opened this issue 5 years ago • 0 comments

I have develop a sketch plugin to upload sketch file to the web server right after the document has been saved but I found when I run upload method in the callback of document.save, sometimes it upload the original document which is unsaved, then I run some test

 let fileData = fs.readFileSync(decodeURIComponent(document.path));
console.log("1:" +  fileData.length);
//do some actions 
//eg. delete some pages 
....
//save the document
document.save(err => {
   fileData = fs.readFileSync(decodeURIComponent(document.path));
   console.log("2:" + fileData.length);
   setTimeout(() => {
      fileData = fs.readFileSync(decodeURIComponent(document.path));
      console.log("3:" + fileData.length);
   }, 4000)
})

It seems the data length(1 and 2) is actually the same right after the save callback is running, after a 4000ms time out(3) ,the file data is actually changed.

But I think the document is supposed to change right after the callback has been executed

funfungo avatar Jun 29 '20 12:06 funfungo