@effect/cluster 0.53.2 → 0.53.3
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.
- package/dist/cjs/EntityResource.js +19 -19
- package/dist/cjs/EntityResource.js.map +1 -1
- package/dist/dts/EntityResource.d.ts +14 -11
- package/dist/dts/EntityResource.d.ts.map +1 -1
- package/dist/esm/EntityResource.js +17 -18
- package/dist/esm/EntityResource.js.map +1 -1
- package/package.json +3 -3
- package/src/EntityResource.ts +23 -32
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.make = exports.TypeId = void 0;
|
|
6
|
+
exports.make = exports.TypeId = exports.CloseScope = void 0;
|
|
7
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
7
8
|
var Duration = _interopRequireWildcard(require("effect/Duration"));
|
|
8
9
|
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
9
10
|
var _Function = require("effect/Function");
|
|
@@ -20,6 +21,15 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
20
21
|
* @category Type ids
|
|
21
22
|
*/
|
|
22
23
|
const TypeId = exports.TypeId = "~@effect/cluster/EntityResource";
|
|
24
|
+
/**
|
|
25
|
+
* A `Scope` that is only closed when the resource is explicitly closed.
|
|
26
|
+
*
|
|
27
|
+
* It is not closed during restarts, due to shard movement or node shutdowns.
|
|
28
|
+
*
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
* @category Scope
|
|
31
|
+
*/
|
|
32
|
+
class CloseScope extends /*#__PURE__*/Context.Tag("@effect/cluster/EntityResource/CloseScope")() {}
|
|
23
33
|
/**
|
|
24
34
|
* A `EntityResource` is a resource that can be acquired inside a cluster
|
|
25
35
|
* entity, which will keep the entity alive even across restarts.
|
|
@@ -33,29 +43,19 @@ const TypeId = exports.TypeId = "~@effect/cluster/EntityResource";
|
|
|
33
43
|
* @since 1.0.0
|
|
34
44
|
* @category Constructors
|
|
35
45
|
*/
|
|
46
|
+
exports.CloseScope = CloseScope;
|
|
36
47
|
const make = exports.make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
37
|
-
const shutdownMode = options.shutdownMode ?? "always";
|
|
38
48
|
let shuttingDown = false;
|
|
39
49
|
const ref = yield* RcRef.make({
|
|
40
50
|
acquire: Effect.gen(function* () {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
yield*
|
|
46
|
-
|
|
47
|
-
yield* Scope.close(closeable, exit);
|
|
48
|
-
yield* Entity.keepAlive(false);
|
|
49
|
-
}, Effect.provide(context)));
|
|
50
|
-
scope = closeable;
|
|
51
|
-
} else {
|
|
52
|
-
yield* Effect.addFinalizer(() => {
|
|
53
|
-
if (shuttingDown) return Effect.void;
|
|
54
|
-
return Entity.keepAlive(false);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
51
|
+
const closeable = yield* Scope.make();
|
|
52
|
+
yield* Effect.addFinalizer(Effect.fnUntraced(function* (exit) {
|
|
53
|
+
if (shuttingDown) return;
|
|
54
|
+
yield* Scope.close(closeable, exit);
|
|
55
|
+
yield* Entity.keepAlive(false);
|
|
56
|
+
}));
|
|
57
57
|
yield* Entity.keepAlive(true);
|
|
58
|
-
return yield* options.acquire.pipe(
|
|
58
|
+
return yield* options.acquire.pipe(Effect.provideService(CloseScope, closeable));
|
|
59
59
|
}),
|
|
60
60
|
idleTimeToLive: options.idleTimeToLive ?? Duration.infinity
|
|
61
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityResource.js","names":["
|
|
1
|
+
{"version":3,"file":"EntityResource.js","names":["Context","_interopRequireWildcard","require","Duration","Effect","_Function","RcRef","Scope","Entity","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TypeId","exports","CloseScope","Tag","make","fnUntraced","options","shuttingDown","ref","acquire","gen","closeable","addFinalizer","exit","close","keepAlive","pipe","provideService","idleTimeToLive","infinity","void","scoped","identity","invalidate"],"sources":["../../src/EntityResource.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,MAAA,GAAAP,uBAAA,CAAAC,OAAA;AAAqC,SAAAD,wBAAAQ,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAQ,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CA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OAAO3C,MAAM,CAACoC,YAAY,CAAC,MAAK;IAC9BL,YAAY,GAAG,IAAI;IACnB,OAAO/B,MAAM,CAAC4C,IAAI;EACpB,CAAC,CAAC;EAEF;EACA,OAAO5C,MAAM,CAAC6C,MAAM,CAAC3C,KAAK,CAACe,GAAG,CAACe,GAAG,CAAC,CAAC;EAEpC,OAAO,IAAAc,kBAAQ,EAAuB;IACpC,CAACtB,MAAM,GAAGA,MAAM;IAChBP,GAAG,EAAEf,KAAK,CAACe,GAAG,CAACe,GAAG,CAAC;IACnBM,KAAK,EAAEpC,KAAK,CAAC6C,UAAU,CAACf,GAAG;GAC5B,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Context from "effect/Context";
|
|
4
5
|
import * as Duration from "effect/Duration";
|
|
5
6
|
import * as Effect from "effect/Effect";
|
|
6
7
|
import * as Scope from "effect/Scope";
|
|
@@ -25,6 +26,17 @@ export interface EntityResource<out A, out E = never> {
|
|
|
25
26
|
readonly get: Effect.Effect<A, E, Scope.Scope>;
|
|
26
27
|
readonly close: Effect.Effect<void>;
|
|
27
28
|
}
|
|
29
|
+
declare const CloseScope_base: Context.TagClass<CloseScope, "@effect/cluster/EntityResource/CloseScope", Scope.Scope>;
|
|
30
|
+
/**
|
|
31
|
+
* A `Scope` that is only closed when the resource is explicitly closed.
|
|
32
|
+
*
|
|
33
|
+
* It is not closed during restarts, due to shard movement or node shutdowns.
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @category Scope
|
|
37
|
+
*/
|
|
38
|
+
export declare class CloseScope extends CloseScope_base {
|
|
39
|
+
}
|
|
28
40
|
/**
|
|
29
41
|
* A `EntityResource` is a resource that can be acquired inside a cluster
|
|
30
42
|
* entity, which will keep the entity alive even across restarts.
|
|
@@ -41,15 +53,6 @@ export interface EntityResource<out A, out E = never> {
|
|
|
41
53
|
export declare const make: <A, E, R>(options: {
|
|
42
54
|
readonly acquire: Effect.Effect<A, E, R>;
|
|
43
55
|
readonly idleTimeToLive?: Duration.DurationInput | undefined;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* If set to "explicit", the resource will only be cleaned up when either the
|
|
48
|
-
* `idleTimeToLive` is reached, or the .close effect is called.
|
|
49
|
-
*
|
|
50
|
-
* Defaults to "always", which means the resource will be cleaned up when the
|
|
51
|
-
* the parent Scope is closed.
|
|
52
|
-
*/
|
|
53
|
-
readonly shutdownMode?: "explicit" | "always" | undefined;
|
|
54
|
-
}) => Effect.Effect<EntityResource<A, E>, E, Scope.Scope | R | Sharding | Entity.CurrentAddress>;
|
|
56
|
+
}) => Effect.Effect<EntityResource<A, E>, E, Scope.Scope | Exclude<R, CloseScope> | Sharding | Entity.CurrentAddress>;
|
|
57
|
+
export {};
|
|
55
58
|
//# sourceMappingURL=EntityResource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityResource.d.ts","sourceRoot":"","sources":["../../src/EntityResource.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAA0C,CAAA;AAE/D;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,iCAAiC,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK;IAClD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;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AAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACxC,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAA;CAC7D,KAAK,MAAM,CAAC,MAAM,CACjB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,CAAC,EACD,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,QAAQ,GAAG,MAAM,CAAC,cAAc,CAyCvE,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Context from "effect/Context";
|
|
4
5
|
import * as Duration from "effect/Duration";
|
|
5
6
|
import * as Effect from "effect/Effect";
|
|
6
7
|
import { identity } from "effect/Function";
|
|
@@ -12,6 +13,15 @@ import * as Entity from "./Entity.js";
|
|
|
12
13
|
* @category Type ids
|
|
13
14
|
*/
|
|
14
15
|
export const TypeId = "~@effect/cluster/EntityResource";
|
|
16
|
+
/**
|
|
17
|
+
* A `Scope` that is only closed when the resource is explicitly closed.
|
|
18
|
+
*
|
|
19
|
+
* It is not closed during restarts, due to shard movement or node shutdowns.
|
|
20
|
+
*
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category Scope
|
|
23
|
+
*/
|
|
24
|
+
export class CloseScope extends /*#__PURE__*/Context.Tag("@effect/cluster/EntityResource/CloseScope")() {}
|
|
15
25
|
/**
|
|
16
26
|
* A `EntityResource` is a resource that can be acquired inside a cluster
|
|
17
27
|
* entity, which will keep the entity alive even across restarts.
|
|
@@ -26,28 +36,17 @@ export const TypeId = "~@effect/cluster/EntityResource";
|
|
|
26
36
|
* @category Constructors
|
|
27
37
|
*/
|
|
28
38
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
29
|
-
const shutdownMode = options.shutdownMode ?? "always";
|
|
30
39
|
let shuttingDown = false;
|
|
31
40
|
const ref = yield* RcRef.make({
|
|
32
41
|
acquire: Effect.gen(function* () {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
yield*
|
|
38
|
-
|
|
39
|
-
yield* Scope.close(closeable, exit);
|
|
40
|
-
yield* Entity.keepAlive(false);
|
|
41
|
-
}, Effect.provide(context)));
|
|
42
|
-
scope = closeable;
|
|
43
|
-
} else {
|
|
44
|
-
yield* Effect.addFinalizer(() => {
|
|
45
|
-
if (shuttingDown) return Effect.void;
|
|
46
|
-
return Entity.keepAlive(false);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
42
|
+
const closeable = yield* Scope.make();
|
|
43
|
+
yield* Effect.addFinalizer(Effect.fnUntraced(function* (exit) {
|
|
44
|
+
if (shuttingDown) return;
|
|
45
|
+
yield* Scope.close(closeable, exit);
|
|
46
|
+
yield* Entity.keepAlive(false);
|
|
47
|
+
}));
|
|
49
48
|
yield* Entity.keepAlive(true);
|
|
50
|
-
return yield* options.acquire.pipe(
|
|
49
|
+
return yield* options.acquire.pipe(Effect.provideService(CloseScope, closeable));
|
|
51
50
|
}),
|
|
52
51
|
idleTimeToLive: options.idleTimeToLive ?? Duration.infinity
|
|
53
52
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityResource.js","names":["Duration","Effect","identity","RcRef","Scope","Entity","TypeId","make","fnUntraced","options","
|
|
1
|
+
{"version":3,"file":"EntityResource.js","names":["Context","Duration","Effect","identity","RcRef","Scope","Entity","TypeId","CloseScope","Tag","make","fnUntraced","options","shuttingDown","ref","acquire","gen","closeable","addFinalizer","exit","close","keepAlive","pipe","provideService","idleTimeToLive","infinity","void","scoped","get","invalidate"],"sources":["../../src/EntityResource.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;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B,MAAM,CAACvB,KAAK,CAACwB,GAAG,CAACd,GAAG,CAAC,CAAC;EAEpC,OAAOX,QAAQ,CAAuB;IACpC,CAACI,MAAM,GAAGA,MAAM;IAChBqB,GAAG,EAAExB,KAAK,CAACwB,GAAG,CAACd,GAAG,CAAC;IACnBM,KAAK,EAAEhB,KAAK,CAACyB,UAAU,CAACf,GAAG;GAC5B,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/cluster",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.3",
|
|
4
4
|
"description": "Unified interfaces for common cluster-specific services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@effect/platform": "^0.93.3",
|
|
15
15
|
"@effect/sql": "^0.48.0",
|
|
16
|
+
"@effect/rpc": "^0.72.2",
|
|
16
17
|
"@effect/workflow": "^0.13.0",
|
|
17
|
-
"effect": "^3.19.6"
|
|
18
|
-
"@effect/rpc": "^0.72.2"
|
|
18
|
+
"effect": "^3.19.6"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"provenance": true
|
package/src/EntityResource.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import * as Context from "effect/Context"
|
|
4
5
|
import * as Duration from "effect/Duration"
|
|
5
6
|
import * as Effect from "effect/Effect"
|
|
6
7
|
import { identity } from "effect/Function"
|
|
@@ -31,6 +32,19 @@ export interface EntityResource<out A, out E = never> {
|
|
|
31
32
|
readonly close: Effect.Effect<void>
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* A `Scope` that is only closed when the resource is explicitly closed.
|
|
37
|
+
*
|
|
38
|
+
* It is not closed during restarts, due to shard movement or node shutdowns.
|
|
39
|
+
*
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
* @category Scope
|
|
42
|
+
*/
|
|
43
|
+
export class CloseScope extends Context.Tag("@effect/cluster/EntityResource/CloseScope")<
|
|
44
|
+
CloseScope,
|
|
45
|
+
Scope.Scope
|
|
46
|
+
>() {}
|
|
47
|
+
|
|
34
48
|
/**
|
|
35
49
|
* A `EntityResource` is a resource that can be acquired inside a cluster
|
|
36
50
|
* entity, which will keep the entity alive even across restarts.
|
|
@@ -47,55 +61,32 @@ export interface EntityResource<out A, out E = never> {
|
|
|
47
61
|
export const make: <A, E, R>(options: {
|
|
48
62
|
readonly acquire: Effect.Effect<A, E, R>
|
|
49
63
|
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
|
50
|
-
/**
|
|
51
|
-
* When to close the resource Scope.
|
|
52
|
-
*
|
|
53
|
-
* If set to "explicit", the resource will only be cleaned up when either the
|
|
54
|
-
* `idleTimeToLive` is reached, or the .close effect is called.
|
|
55
|
-
*
|
|
56
|
-
* Defaults to "always", which means the resource will be cleaned up when the
|
|
57
|
-
* the parent Scope is closed.
|
|
58
|
-
*/
|
|
59
|
-
readonly shutdownMode?: "explicit" | "always" | undefined
|
|
60
64
|
}) => Effect.Effect<
|
|
61
65
|
EntityResource<A, E>,
|
|
62
66
|
E,
|
|
63
|
-
Scope.Scope | R | Sharding | Entity.CurrentAddress
|
|
67
|
+
Scope.Scope | Exclude<R, CloseScope> | Sharding | Entity.CurrentAddress
|
|
64
68
|
> = Effect.fnUntraced(function*<A, E, R>(options: {
|
|
65
69
|
readonly acquire: Effect.Effect<A, E, R>
|
|
66
70
|
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
|
67
|
-
readonly shutdownMode?: "explicit" | "always" | undefined
|
|
68
71
|
}) {
|
|
69
|
-
const shutdownMode = options.shutdownMode ?? "always"
|
|
70
72
|
let shuttingDown = false
|
|
71
73
|
|
|
72
74
|
const ref = yield* RcRef.make({
|
|
73
75
|
acquire: Effect.gen(function*() {
|
|
74
|
-
|
|
76
|
+
const closeable = yield* Scope.make()
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Effect.fnUntraced(function*(exit) {
|
|
82
|
-
if (shuttingDown) return
|
|
83
|
-
yield* Scope.close(closeable, exit)
|
|
84
|
-
yield* Entity.keepAlive(false)
|
|
85
|
-
}, Effect.provide(context))
|
|
86
|
-
)
|
|
87
|
-
scope = closeable
|
|
88
|
-
} else {
|
|
89
|
-
yield* Effect.addFinalizer(() => {
|
|
90
|
-
if (shuttingDown) return Effect.void
|
|
91
|
-
return Entity.keepAlive(false)
|
|
78
|
+
yield* Effect.addFinalizer(
|
|
79
|
+
Effect.fnUntraced(function*(exit) {
|
|
80
|
+
if (shuttingDown) return
|
|
81
|
+
yield* Scope.close(closeable, exit)
|
|
82
|
+
yield* Entity.keepAlive(false)
|
|
92
83
|
})
|
|
93
|
-
|
|
84
|
+
)
|
|
94
85
|
|
|
95
86
|
yield* Entity.keepAlive(true)
|
|
96
87
|
|
|
97
88
|
return yield* options.acquire.pipe(
|
|
98
|
-
|
|
89
|
+
Effect.provideService(CloseScope, closeable)
|
|
99
90
|
)
|
|
100
91
|
}),
|
|
101
92
|
idleTimeToLive: options.idleTimeToLive ?? Duration.infinity
|