-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplayground.js
More file actions
51 lines (49 loc) · 1014 Bytes
/
Copy pathplayground.js
File metadata and controls
51 lines (49 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { setTimeout } from 'node:timers/promises'
import grfn from './src/index.js'
const withLogging = fn =>
Object.defineProperty(
async (...args) => {
console.log(`${fn.name} input: ${args.join(`, `)}`)
const output = await fn(...args)
console.log(`${fn.name} output: ${output}`)
return output
},
`name`,
{
enumerable: false,
writable: false,
value: fn.name,
},
)
const fn = grfn({
e: [
withLogging(async (a, c, d) => {
await setTimeout(10)
return a * c * d
}),
[`a`, `c`, `d`],
],
d: [
withLogging(async b => {
await setTimeout(1)
return b * 2
}),
[`b`],
],
c: [
withLogging(async (a, b) => {
await setTimeout(5)
return a + b
}),
[`a`, `b`],
],
a: withLogging(async (n1, n2, n3) => {
await setTimeout(15)
return n1 + n2 + n3
}),
b: withLogging(async (n1, n2, n3) => {
await setTimeout(10)
return n1 * n2 * n3
}),
})
await fn(1, 2, 3)