3434 */
3535
3636import { InvalidParametersError , serviceCapabilities } from '@libp2p/interface'
37+ import { isAsyncGenerator } from '@libp2p/utils/is-async-generator'
38+ import { isGenerator } from '@libp2p/utils/is-generator'
39+ import { isPromise } from '@libp2p/utils/is-promise'
3740import { trace , metrics , context , SpanStatusCode } from '@opentelemetry/api'
3841import each from 'it-foreach'
3942import { OpenTelemetryCounterGroup } from './counter-group.js'
@@ -438,10 +441,6 @@ export function openTelemetryMetrics (init: OpenTelemetryMetricsInit = {}): (com
438441 return ( components : OpenTelemetryComponents ) => new OpenTelemetryMetrics ( components , init )
439442}
440443
441- function isPromise < T = any > ( obj ?: any ) : obj is Promise < T > {
442- return typeof obj ?. then === 'function'
443- }
444-
445444async function wrapPromise ( promise : Promise < any > , span : Span , attributes : TraceAttributes , options ?: TraceFunctionOptions < any , any > ) : Promise < any > {
446445 return promise
447446 . then ( res => {
@@ -458,10 +457,6 @@ async function wrapPromise (promise: Promise<any>, span: Span, attributes: Trace
458457 } )
459458}
460459
461- function isGenerator ( obj ?: any ) : obj is Generator {
462- return obj ?. [ Symbol . iterator ] != null
463- }
464-
465460function wrapGenerator ( gen : Generator , span : Span , attributes : TraceAttributes , options ?: TraceGeneratorFunctionOptions < any , any , any > ) : Generator {
466461 const iter = gen [ Symbol . iterator ] ( )
467462 let index = 0
@@ -502,10 +497,6 @@ function wrapGenerator (gen: Generator, span: Span, attributes: TraceAttributes,
502497 return wrapped
503498}
504499
505- function isAsyncGenerator ( obj ?: any ) : obj is AsyncGenerator {
506- return obj ?. [ Symbol . asyncIterator ] != null
507- }
508-
509500function wrapAsyncGenerator ( gen : AsyncGenerator , span : Span , attributes : TraceAttributes , options ?: TraceGeneratorFunctionOptions < any , any , any > ) : AsyncGenerator {
510501 const iter = gen [ Symbol . asyncIterator ] ( )
511502 let index = 0
0 commit comments