Skip to content

Instantly share code, notes, and snippets.

@jeromew
jeromew / Readme.md
Last active January 2, 2016 18:09
koa with a delay middleware : how a slow middleware impacts streaming

Currently in koa (09/01/2014), streaming data to the network begins only after the middleware stack has been fully traversed.

If the flow through the middleware stack takes N seconds then a stream created on this.body may buffer data in memory for N seconds.

Since any call to "yield myPromise" pauses the flow until myPromise resolves, streams may start buffering in memory until all middleware promises are resolved.

It is probably better to start streaming data only late in the middleware stack in order to avoid slower promises (database access for instance).

In the following flow :

var h = require("highland");
var net = require("net");
var HOST = "127.0.0.1";
function createWorker(port, maxClients) {
var w = net.createServer();
var clients = 0;
h('connection', w)
@jeromew
jeromew / babel-plugin-pug-concat.js
Created February 1, 2019 15:37
babel plugin that compacts contiguous pug_html = pug_html + ... sequences
'use strict';
var t = require('babel-types');
var stringify = require('js-stringify');
function isPugAssignment(path) {
if (!t.isAssignmentExpression(path)) {
return;
}
if (!t.isIdentifier(path.get('left')) ||