Skip to content

Proposal: making render() async #469

Open
@lordofthelake

Description

@lordofthelake

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions