34
34
*/
35
35
36
36
import { 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'
37
40
import { trace , metrics , context , SpanStatusCode } from '@opentelemetry/api'
38
41
import each from 'it-foreach'
39
42
import { OpenTelemetryCounterGroup } from './counter-group.js'
@@ -438,10 +441,6 @@ export function openTelemetryMetrics (init: OpenTelemetryMetricsInit = {}): (com
438
441
return ( components : OpenTelemetryComponents ) => new OpenTelemetryMetrics ( components , init )
439
442
}
440
443
441
- function isPromise < T = any > ( obj ?: any ) : obj is Promise < T > {
442
- return typeof obj ?. then === 'function'
443
- }
444
-
445
444
async function wrapPromise ( promise : Promise < any > , span : Span , attributes : TraceAttributes , options ?: TraceFunctionOptions < any , any > ) : Promise < any > {
446
445
return promise
447
446
. then ( res => {
@@ -458,10 +457,6 @@ async function wrapPromise (promise: Promise<any>, span: Span, attributes: Trace
458
457
} )
459
458
}
460
459
461
- function isGenerator ( obj ?: any ) : obj is Generator {
462
- return obj ?. [ Symbol . iterator ] != null
463
- }
464
-
465
460
function wrapGenerator ( gen : Generator , span : Span , attributes : TraceAttributes , options ?: TraceGeneratorFunctionOptions < any , any , any > ) : Generator {
466
461
const iter = gen [ Symbol . iterator ] ( )
467
462
let index = 0
@@ -502,10 +497,6 @@ function wrapGenerator (gen: Generator, span: Span, attributes: TraceAttributes,
502
497
return wrapped
503
498
}
504
499
505
- function isAsyncGenerator ( obj ?: any ) : obj is AsyncGenerator {
506
- return obj ?. [ Symbol . asyncIterator ] != null
507
- }
508
-
509
500
function wrapAsyncGenerator ( gen : AsyncGenerator , span : Span , attributes : TraceAttributes , options ?: TraceGeneratorFunctionOptions < any , any , any > ) : AsyncGenerator {
510
501
const iter = gen [ Symbol . asyncIterator ] ( )
511
502
let index = 0
0 commit comments