Asynchronous plugin support #2

Closed
simenbrekken opened this Issue Sep 3, 2012 · 11 comments

Comments

Projects
None yet
4 participants
Contributor

simenbrekken commented Sep 3, 2012

Currently all plugins are expected to be synchronous which works fine when your only requirement is the CSS AST itself, but it would be great if plugins could also be asynchronous, for things more advanced plugins like:

Automatic generation of standard resolution images when retina version exists

  1. atx plugin processes stylesheet and injects retina-specific rules.
  2. magicalretinaplugin scans the AST again, and for every nonexistent background-image declaration inspects the physical image. if the standard image doesn't exist but the retina does, generate @2x image using something like node-canvas.

Automatic sprite-sheet generation

  1. Scan AST for background-image declarations and store dimensions.
  2. Generate spritesheets using bin-packing and then node-canvas for each pixel-ratio.

Image-processing tools

Tools like jpegoptim, optipng and pngcrush.

Owner

tj commented Sep 3, 2012

and node.js callback codesmell begins :D

Contributor

simenbrekken commented Sep 4, 2012

Yes, it would be nice to avoid that all together. I was thinking that it could be done in a way similar to superagent in where you queue tasks to be performed on the AST and execute them in order when you reach end, toString or similar.

Contributor

simenbrekken commented Sep 7, 2012

I've pushed a branch that makes rework plugins asynchronous (and 40% faster according to bench.js). Whenever use is called, the task is pushed to a queue which is processed sequentially by calling end which in turn is used by toString.

https://github.com/unfold/rework/tree/async

Owner

tj commented Sep 7, 2012

there's no way it's faster haha bench.js does no I/O

Contributor

simenbrekken commented Sep 7, 2012

I've converted the branch to use batch now so the error handling should be in place.

Owner

tj commented Sep 7, 2012

sweet, i'll take a look after work

Owner

tj commented Oct 6, 2012

needs rebase :(

I do think this would be really useful, but can we do it in a way that supports synchronous operation when there are now asynchronous pluggins? Perhaps async plugins could mark themselves as async in some way?

:( really want this still

Contributor

jonathanong commented Oct 10, 2013

do you guys have a preferred api for this? i would separate this from .use() and use .queue(plugin) and .end(callback). how do you suggest rework differentiates async plugins from sync ones?

Contributor

jonathanong commented Dec 2, 2013

closing for now unless people have suggestions.

@jonathanong jonathanong closed this Dec 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment