@barnum/barnum 0.0.0-main-bf5fee51 → 0.0.0-main-baf9644f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-resource.d.ts","sourceRoot":"","sources":["../../src/builtins/with-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAY,MAAM,WAAW,CAAC;AAWtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,IAAI,EACJ,WAAW,GAAG,OAAO,EACrB,EACA,MAAM,EACN,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;CAC3C,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"with-resource.d.ts","sourceRoot":"","sources":["../../src/builtins/with-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAY,MAAM,WAAW,CAAC;AAWtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,IAAI,EACJ,WAAW,GAAG,OAAO,EACrB,EACA,MAAM,EACN,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;CAC3C,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CA6BzB"}
|
|
@@ -24,12 +24,13 @@ import { getIndex } from "./array.js";
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export function withResource({ create, action, dispose, }) {
|
|
27
|
-
// Step 1: all(create, identity) → [TResource, TIn]
|
|
28
|
-
const
|
|
29
|
-
// Step 2: all(action,
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// Step 1: all(create, identity) → [TResource, TIn]
|
|
28
|
+
const acquireParallel = all(create, identity());
|
|
29
|
+
// Step 2: all(merge → action, getIndex(0) → keep resource) → [TOut, TResource]
|
|
30
|
+
// Run action on merged input, but keep raw TResource for dispose
|
|
31
|
+
const runActionKeepResource = all(chain(toAction(merge()), toAction(action)), toAction(getIndex(0).unwrap()));
|
|
32
|
+
// Step 3: all(getIndex(0) → TOut, getIndex(1) → dispose) → [TOut, TDisposeOut]
|
|
32
33
|
const disposeAndKeepResult = all(toAction(getIndex(0).unwrap()), chain(toAction(getIndex(1).unwrap()), toAction(dispose)));
|
|
33
34
|
// Step 4: getIndex(0).unwrap() → TOut
|
|
34
|
-
return chain(toAction(chain(toAction(chain(toAction(
|
|
35
|
+
return chain(toAction(chain(toAction(chain(toAction(acquireParallel), toAction(runActionKeepResource))), toAction(disposeAndKeepResult))), toAction(getIndex(0).unwrap()));
|
|
35
36
|
}
|
package/package.json
CHANGED
|
@@ -39,16 +39,17 @@ export function withResource<
|
|
|
39
39
|
action: Pipeable<TResource & TIn, TOut>;
|
|
40
40
|
dispose: Pipeable<TResource, TDisposeOut>;
|
|
41
41
|
}): TypedAction<TIn, TOut> {
|
|
42
|
-
// Step 1: all(create, identity) → [TResource, TIn]
|
|
43
|
-
const
|
|
44
|
-
toAction(all(create, identity())),
|
|
45
|
-
toAction(merge()),
|
|
46
|
-
);
|
|
42
|
+
// Step 1: all(create, identity) → [TResource, TIn]
|
|
43
|
+
const acquireParallel = all(create, identity());
|
|
47
44
|
|
|
48
|
-
// Step 2: all(action,
|
|
49
|
-
|
|
45
|
+
// Step 2: all(merge → action, getIndex(0) → keep resource) → [TOut, TResource]
|
|
46
|
+
// Run action on merged input, but keep raw TResource for dispose
|
|
47
|
+
const runActionKeepResource = all(
|
|
48
|
+
chain(toAction(merge()), toAction(action)),
|
|
49
|
+
toAction(getIndex(0).unwrap()),
|
|
50
|
+
);
|
|
50
51
|
|
|
51
|
-
// Step 3: all(getIndex(0)
|
|
52
|
+
// Step 3: all(getIndex(0) → TOut, getIndex(1) → dispose) → [TOut, TDisposeOut]
|
|
52
53
|
const disposeAndKeepResult = all(
|
|
53
54
|
toAction(getIndex(0).unwrap()),
|
|
54
55
|
chain(toAction(getIndex(1).unwrap()), toAction(dispose)),
|
|
@@ -59,7 +60,7 @@ export function withResource<
|
|
|
59
60
|
toAction(
|
|
60
61
|
chain(
|
|
61
62
|
toAction(
|
|
62
|
-
chain(toAction(
|
|
63
|
+
chain(toAction(acquireParallel), toAction(runActionKeepResource)),
|
|
63
64
|
),
|
|
64
65
|
toAction(disposeAndKeepResult),
|
|
65
66
|
),
|