cacheable icon indicating copy to clipboard operation
cacheable copied to clipboard

How to deal with invalid usage?

Open szmarczak opened this issue 4 years ago • 0 comments

const https = require('https');
const CacheableRequest = require('cacheable-request');

const cacheableRequest = new CacheableRequest(https.request);
const cacheReq = cacheableRequest('https://unpkg.com/[email protected]/dist/vue.js');
cacheReq.on('request', req => {
	req.end();

	// This is invalid usage!!!
	// Instead: cacheableRequest('https://unpkg.com/[email protected]/dist/vue.js', TheResponseCallbackShouldGoHere)
	req.on('response', response => {
		let x = 0;

		// This should be illegal. IOW throw.
		response.on('data', chunk => {
			x += chunk.length;
			console.log(x);
		});
	});
});

szmarczak avatar May 02 '20 11:05 szmarczak