Stylus渲染功能是同步的吗?

lag*_*lex 1 stylus

我正在.styl使用JavaScript API 编译我的Stylus 样式表:http://learnboost.github.io/stylus/docs/js.html

  var stylus = require('../')
    , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8');

  stylus(str)
    .set('filename', __dirname + '/test.styl')
    .import('mixins/vendor')
    .render(function(err, css){
    if (err) throw err;
    console.log(css);
  });
Run Code Online (Sandbox Code Playgroud)

它没有提到它使用的回调是同步还是异步.虽然根据我的经验,它似乎是同步的,但我不确定.是吗?

Pan*_*nya 5

render函数是伪异步的,因为它接受回调,但函数内的所有调用实际上都是同步的.还有一个完全同步的函数版本(如果你不提供回调):

var styl = stylus(str)
  .set('filename', __dirname + '/test.styl')
  .import('mixins/vendor');

console.log(styl.render()); // outputs compiled css
Run Code Online (Sandbox Code Playgroud)