Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created December 23, 2021 11:12
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 mfbx9da4/adf734a854e41f4786c933747b701d14 to your computer and use it in GitHub Desktop.
Save mfbx9da4/adf734a854e41f4786c933747b701d14 to your computer and use it in GitHub Desktop.
const wrap = (obj, method) => {
const oldMethod = obj[method]
async function innerMethod(...args) {
const start = Date.now()
try {
const ret = await oldMethod.call(obj, ...args)
console.log(method, 'took', Date.now() - start, args[0])
return ret
} catch (error) {
console.log(method, 'took', Date.now() - start)
throw error
}
}
Object.assign(obj, { [method]: innerMethod })
}
function wrapMethods(obj) {
for (const method in obj) {
if (typeof obj[method] === 'function') {
wrap(obj, method)
}
}
}
wrapMethods(AsyncStorage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment