Skip to content

Instantly share code, notes, and snippets.

View anonimusprogramus's full-sized avatar

Anonimus Programus anonimusprogramus

View GitHub Profile
@anonimusprogramus
anonimusprogramus / app.js
Last active April 5, 2020 14:03
sirv: reloading Vue's nested routes
// taken from https://router.vuejs.org/guide/#html
const Foo = {
template: `<div>This is Foo</div>`
}
const Bar = {
template: `<div>And this is Bar</div>`
}
// taken from https://jsfiddle.net/posva/22wgksa3/
const UserSettingsNav = {
@anonimusprogramus
anonimusprogramus / terser.js
Created October 11, 2022 09:46 — forked from jrschumacher/terser.js
A terser script to minify all javascript files in a directory
const fs = require('fs')
const {sync: globSync} = require('glob')
const filesize = require('filesize')
const Terser = require('terser')
const options = require(process.env.TERSER_CONFIG || './terserrc.json')
const getSize = (file) => {
const {size} = fs.statSync(file)
return filesize(size)
}

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do: