Created
October 18, 2018 20:58
-
-
Save ericnormand/b76c19b05729a3a793edc4095156a03c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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