- pentium166
- Oct 15, 2012
-
|
Fully unwrapping the initial code sample, you end up with something like this:
TypeScript code:function myMetricsHandler(metrics) {
// metrics is provided by the function that calls myMetricsHandler,
// in this case "metricScope"
return async function butts(input) {
return metrics.someChainedFuncsThatPublishAMetric(input.exampleKey);
}
}
const myPublish = metricScope(myMetricsHandler);
await myPublish({exampleKey: 5})
// Where in the AWS library, metricScope might be defined as something like:
function metricScope(userFunction) {
const metrics = new MetricsService();
return async function (args) {
// first, get the async function returned by myMetricsHandler
const buttsFunction = userFunction(metrics);
// then call that async function with the final arguments ({exampleKey: 5}).
// butts will have access to metrics by virtue of being defined inside
// the closure created by myMetricsHandler
return buttsFunction(args);
}
}
|
#
¿
Jan 23, 2024 16:17
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 12, 2024 17:53
|
|