Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created December 23, 2021 11:12
Embed
What would you like to do?
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