Skip to content

Instantly share code, notes, and snippets.

@DylanPiercey
Last active December 17, 2015 02:56
Show Gist options
  • Save DylanPiercey/b8ccc576251a6d9503ba to your computer and use it in GitHub Desktop.
Save DylanPiercey/b8ccc576251a6d9503ba to your computer and use it in GitHub Desktop.
An Isomorphic lodash snippet.
const _ = require("lodash")
_.chain(emails)
.chunk(100)
.filter("to")
.unshift(Promise.resolve())
.reduce((p, batch)=> {
p.then(()=> {
fetch("http://myapi.com/email", {
method: "POST",
body: JSON.stringify(batch)
});
});
})
.value()
.then(()=> {
console.log("Emails sent!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment