Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add profile zoom & wallet requests, revert Gun.serve
- Loading branch information
1 parent
d1b9f5f
commit e09a001
Showing
7 changed files
with
109 additions
and
42 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { isObject, isFunction } from 'lodash' | ||
import moment from 'moment' | ||
|
||
const profilers = new WeakMap() | ||
|
||
const isPromise = object => isObject(object) && isFunction(object.then) | ||
|
||
export const getProfiler = logger => { | ||
if (!profilers.has(logger)) { | ||
// eslint-disable-next-line require-await | ||
profilers.set(logger, (message, promiseOrFn) => { | ||
const started = new Date() | ||
const onFinished = () => { | ||
const time = moment.duration(moment().diff(started)).as('milliseconds') | ||
|
||
logger.debug(`${message} finished in ${time}ms`) | ||
} | ||
|
||
let result | ||
let promise | ||
|
||
if (isFunction(promiseOrFn)) { | ||
try { | ||
result = promiseOrFn() | ||
|
||
if (isPromise(result)) { | ||
promise = result | ||
} | ||
} catch (exception) { | ||
onFinished() | ||
throw exception | ||
} | ||
} else { | ||
promise = promiseOrFn | ||
} | ||
|
||
if (!promise) { | ||
onFinished() | ||
return result | ||
} | ||
|
||
return promise.finally(onFinished) | ||
}) | ||
} | ||
|
||
return profilers.get(logger) | ||
} |
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
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
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