Proposal: making `render()` async

Author: lordofthelakeCreated Jan 19, 2020Updated Jan 20, 2020

As we discussed in the PR over node-sketch-bridge, I'm working on writing a "pure" implementation of makeImageDataFromUrl(), using fetch and @skpm/fs.

There is one major problem implementing it in this way though: fetch is asynchronous, while the whole rendering operation is synchronous.

Now, I see two ways around this:

  1. I keep pieces of the existing implementation that uses NSData around, and keep everything sync. Not surprisingly, NSData documentation has a big fat warning about not using it for network requests, though, because it can potentially hang the whole thing if the network is slow/unresponsive. The pro is that I can keep the existing interface. The con is that, as per current implementation, it can potentially hang Sketch, and the implementation is less uniform.
  2. Make makeImageDataFromUrl return a Promise and make the whole chain of functions up to render async as well. This allows us to use fetch, makes the whole thing faster in cases where there are multiple images in a layout, and in general less prone to hang, but it's a breaking change.

@mathieudutour Thoughts?