I was trying to search for an answer, but most of the hits I'm getting are for either no parameters or fixed parameters.
What I would like to be able to do is implement an optional callback in a javascript function with an unknown number of parameters and parameter types.
I'm implementing a javascript layer to use AWS temporary credentials to manipulate files on S3. Some function calls upload files (receiving an array), some delete files (also array), some rename a bucket object (with two parameters, old key and new key), etc.
The problem is, when using temporary credentials, the credentials can time out. So before any call is done, I have to check if the credentials need updating. If they do, I have to do an asynchronous call to get the credentials first. Only when the credentials have been retrieved, should it start doing whatever it was asked to do.
Is this what those 'promises' were all about? I haven't worked with those much yet and will be doing reading on them now, but wouldn't have a clue how to implement one (yet).
Basically, in my code, I need a wrapper for any given aws function:
function onDelete(key) {
if(AWS.config.credentials.needsRefresh()) {
refreshToken(); // makes an asynchronous call with jquery
// need to do actual delete when ajax finished: delete(key)
} else {
// do actual delete immediately: delete(key)
}
}
function onRename(oldkey,newkey) {
if(AWS.config.credentials.needsRefresh()) {
refreshToken(); // makes an asynchronous call with jquery
// need to do actual rename when ajax finished: rename(oldkey, newkey)
} else {
// do actual rename immediately: rename(oldkey, newkey)
}
}
Or something along those lines. Any help is appreciated.