AsEjs does pretty much the same thing that EJS templates templates do, with the following delicate differences:
Streaming: Rather than rendering the template completely into a buffer first, and then outputting that buffer to the client, AsEjs templates output chunks of their content directly and immediately into the output stream as soon as that makes sense.
Asynchronous: AsEjs support calling asynchronous methods from within the template, i.e. methods that don't do anything at the time, but return their result at a later time using a callback function. AsEjs templates understand this paradigm and pause the output stream at this point until the callback method gets called. The rendering continues normally after that.
Working examples are given in the example directory.
Here is an example CoffeeScript file that renders a template.
# Load the required libraries.AsyncFuture = require 'async_future.coffee'AsEjs = require 'as_ejs'# Simulate slow database operations.= setTimeout -> done_callbackresultdelayuser_loader = simulate_delay1000'John Doe 'city_loader = simulate_delay2000'Los Angeles'# The name of the template file to render.template_filename = './template.as_ejs'# The data that should be rendered into the template.data = user: user_loadercity: city_loader# The template writes output by calling this function.out_stream = consolelog# The template calls this function when it is done rendering.= -> consolelog '\n\n[rending finished]'consolelog '[rendering start]\n'AsEjsrender_file template_filenamedataconsolelogdone_callback
Here is the corresponding template.