Created
September 23, 2015 07:20
-
-
Save xicond/9f8bcb33d66c789b866d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var app = require('express')(), | |
swig = require('swig'), | |
async = require("async"), | |
sleep = require('sleep'), | |
people; | |
// This is where all the magic happens! | |
app.engine('html', swig.renderFile); | |
app.set('view engine', 'html'); | |
app.set('views', __dirname + '/views'); | |
// Swig will cache templates for you, but you can disable | |
// that and use Express's caching instead, if you like: | |
app.set('view cache', false); | |
// To disable Swig's cache, do the following: | |
swig.setDefaults({ cache: false }); | |
// NOTE: You should always cache templates in a production environment. | |
// Don't leave both of these to `false` in production! | |
app.get('/', function (req, res) { | |
var locals = [], asyncTasks = []; | |
var q = async.queue(function (task, callback) { | |
// console.log('hello ' + task.name); | |
callback(); | |
}, 100); | |
for (var i=1; i<=5000; i++){ | |
locals.push(i); | |
q.push({name: 'foo'+i}, function (err) { | |
for(var j=10000; j<=100000; j++){ | |
locals[i-1] = locals[i-1]+j ; | |
} | |
// console.log(locals[i-1]); | |
// callback(null, 'folder'); | |
}); | |
} | |
/*async.parallel(asyncTasks, function(){ | |
// All tasks are done now | |
console.log('in'); | |
res.render('index', { *//* template locals context *//* }); | |
res.end(); | |
});*/ | |
q.process(); | |
while(q.length())sleep.usleep(1000); | |
// res. | |
res.render('index', { /* template locals context */ }); | |
}); | |
app.listen(1337); | |
console.log('Application Started on http://localhost:1337/'); |
{# views/layout.html #}
<!doctype html>
{% block head %}
<link rel="stylesheet" href="main.css">
{% endblock %}
{% block content %}{% endblock %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{% extends 'layout.html' %}
{# views/index.html #}
{% block title %}My Page{% endblock %}
{% block head %}
{% endblock %}{% parent %}
{% block content %}
This is just an awesome page.
{% endblock %}