Skip to content

Instantly share code, notes, and snippets.

@ericnormand
Created October 18, 2018 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericnormand/b76c19b05729a3a793edc4095156a03c to your computer and use it in GitHub Desktop.
Save ericnormand/b76c19b05729a3a793edc4095156a03c to your computer and use it in GitHub Desktop.
// takes a function of one or more arguments
// the first argument has to be the id
function make_idempotent(f) {
const already_performed = {};
return function(id, ...args) {
if(already_performed[id])
return {status: "already performed"};
already_performed[id] = true;
return {
status: "performing",
return_value: f(id, ...args)
};
};
}
function send_email(id, to, subject, body) {
// ... implementation here
}
const send_email_idemp = make_idempotent(send_email);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment