• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Node-In-Layers / nil-core / 22237577759

20 Feb 2026 07:12PM UTC coverage: 88.92% (-0.2%) from 89.153%
22237577759

push

github

web-flow
Merge pull request #24 from Node-In-Layers/otel

Otel

508 of 579 branches covered (87.74%)

Branch coverage included in aggregate %.

1225 of 1625 new or added lines in 15 files covered. (75.38%)

6 existing lines in 3 files now uncovered.

3914 of 4394 relevant lines covered (89.08%)

94.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.5
/src/utils.ts
1
import merge from 'lodash/merge.js'
3✔
2
import { v4 } from 'uuid'
3✔
3
import AsyncLock from 'async-lock'
3✔
4
import type { RequiresInitialization } from './types.js'
3✔
5

3✔
6
export const wrap = <T extends Array<any>, U>(fn: (...args: T) => U) => {
3✔
7
  return merge((...args: T): U => fn(...args), fn)
3✔
8
}
3✔
9

3✔
10
export const isPromise = <T>(obj: any): obj is Promise<T> => {
3✔
11
  return Boolean(obj && obj.then)
9✔
12
}
9✔
13

3✔
14
export const promiseWrap = <T extends Array<any>, U>(
3✔
15
  fn: (...args: T) => Promise<U> | U
3✔
16
) => {
3✔
17
  return merge(
3✔
18
    (...args: T): Promise<U> => Promise.resolve().then(() => fn(...args)),
3✔
19
    fn
3✔
20
  )
3✔
21
}
3✔
22

3✔
23
export const memoizeValueSync = <T, A extends Array<any>>(
3✔
24
  method: (...args: A) => T
3✔
25
) => {
3,705✔
26
  /* eslint-disable functional/no-let */
3,705✔
27
  let value: any = undefined
3,705✔
28
  let called = false
3,705✔
29
  return (...args: A) => {
3,705✔
30
    if (!called) {
240✔
31
      value = method(...args)
168✔
32
      // This is very important that it goes afterwards. Sometimes this will throw an exception.
168✔
33
      // and if one caller happened to catch it and move on, then this will never throw again, which
168✔
34
      // likely means that we won't know what the heck happened.
168✔
35
      called = true
168✔
36
    }
168✔
37

240✔
38
    return value
240✔
39
  }
240✔
40
  /* eslint-enable functional/no-let */
3,705✔
41
}
3,705✔
42

3✔
43
export const memoizeValue = <T, A extends Array<any>>(
3✔
44
  method: (...args: A) => T | Promise<T>
3✔
45
): ((...args: A) => Promise<T>) => {
15✔
46
  const key = v4()
15✔
47
  const lock = new AsyncLock()
15✔
48
  /* eslint-disable functional/no-let */
15✔
49
  let value: any = undefined
15✔
50
  let called = false
15✔
51
  return async (...args: A) => {
15✔
52
    return lock.acquire(key, async () => {
3✔
53
      if (!called) {
3✔
54
        value = await method(...args)
3✔
55
        // Read above about this.
3✔
56
        // eslint-disable-next-line require-atomic-updates
3✔
57
        called = true
3✔
58
      }
3✔
59

3✔
60
      return value as T
3✔
61
    })
3✔
62
  }
3✔
63
  /* eslint-enable functional/no-let */
15✔
64
}
15✔
65

3✔
66
/**
3✔
67
 * Wraps an object that needs to be explicitly initialized before use.
3✔
68
 * @param initializer - A function that returns a promise of the object to be initialized.
3✔
69
 * @returns A RequiresInitialization object.
3✔
70
 */
3✔
71
export const requiresInitialization = <T>(
3✔
72
  initializer: () => Promise<T>
3✔
73
): RequiresInitialization<T> => {
9✔
74
  // eslint-disable-next-line functional/no-let
9✔
75
  let initialized = false
9✔
76
  // eslint-disable-next-line functional/no-let
9✔
77
  let instance: T | undefined = undefined
9✔
78

9✔
79
  const initialize = async () => {
9✔
80
    instance = await initializer()
9✔
81
    initialized = true
9✔
82
  }
9✔
83

9✔
84
  const getInstance = (): T => {
9✔
NEW
85
    if (!initialized) {
×
NEW
86
      throw new Error('Instance not initialized')
×
NEW
87
    }
×
NEW
88
    return instance as unknown as T
×
NEW
89
  }
×
90

9✔
91
  return {
9✔
92
    isInitialized: () => initialized,
9✔
93
    getInstance,
9✔
94
    initialize,
9✔
95
  }
9✔
96
}
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc