@effect/platform 0.53.14 → 0.55.0
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/README.md +269 -38
- package/dist/cjs/Worker.js.map +1 -1
- package/dist/cjs/WorkerError.js +2 -14
- package/dist/cjs/WorkerError.js.map +1 -1
- package/dist/cjs/internal/worker.js +13 -12
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/Http/Client.d.ts +2 -2
- package/dist/dts/Http/IncomingMessage.d.ts +4 -4
- package/dist/dts/Http/Multipart.d.ts +1 -1
- package/dist/dts/Http/Router.d.ts +2 -2
- package/dist/dts/Http/ServerRequest.d.ts +6 -6
- package/dist/dts/KeyValueStore.d.ts +4 -4
- package/dist/dts/Transferable.d.ts +1 -1
- package/dist/dts/Worker.d.ts +13 -18
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/WorkerError.d.ts +2 -2
- package/dist/dts/WorkerError.d.ts.map +1 -1
- package/dist/esm/Worker.js.map +1 -1
- package/dist/esm/WorkerError.js +1 -13
- package/dist/esm/WorkerError.js.map +1 -1
- package/dist/esm/internal/worker.js +13 -12
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +3 -3
- package/src/Http/Client.ts +1 -1
- package/src/Http/IncomingMessage.ts +4 -4
- package/src/Http/Multipart.ts +1 -1
- package/src/Http/Router.ts +2 -2
- package/src/Http/ServerRequest.ts +6 -6
- package/src/KeyValueStore.ts +4 -4
- package/src/Transferable.ts +2 -2
- package/src/Worker.ts +16 -22
- package/src/WorkerError.ts +3 -18
- package/src/internal/http/multipart.ts +1 -1
- package/src/internal/http/router.ts +2 -2
- package/src/internal/http/serverRequest.ts +6 -6
- package/src/internal/keyValueStore.ts +2 -2
- package/src/internal/worker.ts +18 -35
|
@@ -133,7 +133,7 @@ export const upgradeChannel: <IE = never>() => Channel<
|
|
|
133
133
|
* @since 1.0.0
|
|
134
134
|
* @category schema
|
|
135
135
|
*/
|
|
136
|
-
export const schemaCookies: <
|
|
136
|
+
export const schemaCookies: <A, I extends Readonly<Record<string, string>>, R>(
|
|
137
137
|
schema: Schema.Schema<A, I, R>,
|
|
138
138
|
options?: ParseOptions | undefined
|
|
139
139
|
) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaCookies
|
|
@@ -142,7 +142,7 @@ export const schemaCookies: <R, I extends Readonly<Record<string, string>>, A>(
|
|
|
142
142
|
* @since 1.0.0
|
|
143
143
|
* @category schema
|
|
144
144
|
*/
|
|
145
|
-
export const schemaHeaders: <
|
|
145
|
+
export const schemaHeaders: <A, I extends Readonly<Record<string, string>>, R>(
|
|
146
146
|
schema: Schema.Schema<A, I, R>,
|
|
147
147
|
options?: ParseOptions | undefined
|
|
148
148
|
) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaHeaders
|
|
@@ -151,7 +151,7 @@ export const schemaHeaders: <R, I extends Readonly<Record<string, string>>, A>(
|
|
|
151
151
|
* @since 1.0.0
|
|
152
152
|
* @category schema
|
|
153
153
|
*/
|
|
154
|
-
export const schemaSearchParams: <
|
|
154
|
+
export const schemaSearchParams: <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
|
|
155
155
|
schema: Schema.Schema<A, I, R>,
|
|
156
156
|
options?: ParseOptions | undefined
|
|
157
157
|
) => Effect.Effect<A, ParseResult.ParseError, ParsedSearchParams | R> = internal.schemaSearchParams
|
|
@@ -169,7 +169,7 @@ export const schemaBodyJson: <A, I, R>(
|
|
|
169
169
|
* @since 1.0.0
|
|
170
170
|
* @category schema
|
|
171
171
|
*/
|
|
172
|
-
export const schemaBodyForm: <
|
|
172
|
+
export const schemaBodyForm: <A, I extends Partial<Multipart.Persisted>, R>(
|
|
173
173
|
schema: Schema.Schema<A, I, R>,
|
|
174
174
|
options?: ParseOptions | undefined
|
|
175
175
|
) => Effect.Effect<
|
|
@@ -182,7 +182,7 @@ export const schemaBodyForm: <R, I extends Partial<Multipart.Persisted>, A>(
|
|
|
182
182
|
* @since 1.0.0
|
|
183
183
|
* @category schema
|
|
184
184
|
*/
|
|
185
|
-
export const schemaBodyUrlParams: <
|
|
185
|
+
export const schemaBodyUrlParams: <A, I extends Readonly<Record<string, string>>, R>(
|
|
186
186
|
schema: Schema.Schema<A, I, R>,
|
|
187
187
|
options?: ParseOptions | undefined
|
|
188
188
|
) => Effect.Effect<A, ParseResult.ParseError | Error.RequestError, R | ServerRequest> = internal.schemaBodyUrlParams
|
|
@@ -191,7 +191,7 @@ export const schemaBodyUrlParams: <R, I extends Readonly<Record<string, string>>
|
|
|
191
191
|
* @since 1.0.0
|
|
192
192
|
* @category schema
|
|
193
193
|
*/
|
|
194
|
-
export const schemaBodyMultipart: <
|
|
194
|
+
export const schemaBodyMultipart: <A, I extends Partial<Multipart.Persisted>, R>(
|
|
195
195
|
schema: Schema.Schema<A, I, R>,
|
|
196
196
|
options?: ParseOptions | undefined
|
|
197
197
|
) => Effect.Effect<
|
package/src/KeyValueStore.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface KeyValueStore {
|
|
|
76
76
|
/**
|
|
77
77
|
* Create a SchemaStore for the specified schema.
|
|
78
78
|
*/
|
|
79
|
-
readonly forSchema: <A, I, R>(schema: Schema.Schema<A, I, R>) => SchemaStore<
|
|
79
|
+
readonly forSchema: <A, I, R>(schema: Schema.Schema<A, I, R>) => SchemaStore<A, R>
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
@@ -143,7 +143,7 @@ export type SchemaStoreTypeId = typeof SchemaStoreTypeId
|
|
|
143
143
|
* @since 1.0.0
|
|
144
144
|
* @category models
|
|
145
145
|
*/
|
|
146
|
-
export interface SchemaStore<
|
|
146
|
+
export interface SchemaStore<A, R> {
|
|
147
147
|
readonly [SchemaStoreTypeId]: SchemaStoreTypeId
|
|
148
148
|
/**
|
|
149
149
|
* Returns the value of the specified key if it exists.
|
|
@@ -202,6 +202,6 @@ export const layerSchema: <A, I, R>(
|
|
|
202
202
|
schema: Schema.Schema<A, I, R>,
|
|
203
203
|
tagIdentifier: string
|
|
204
204
|
) => {
|
|
205
|
-
readonly tag: Context.Tag<SchemaStore<
|
|
206
|
-
readonly layer: Layer.Layer<SchemaStore<
|
|
205
|
+
readonly tag: Context.Tag<SchemaStore<A, R>, SchemaStore<A, R>>
|
|
206
|
+
readonly layer: Layer.Layer<SchemaStore<A, R>, never, KeyValueStore>
|
|
207
207
|
} = internal.layerSchema
|
package/src/Transferable.ts
CHANGED
|
@@ -82,11 +82,11 @@ export const schema: {
|
|
|
82
82
|
<I>(
|
|
83
83
|
f: (_: I) => Iterable<globalThis.Transferable>
|
|
84
84
|
): <A, R>(self: Schema.Schema<A, I, R>) => Schema.Schema<A, I, R>
|
|
85
|
-
<
|
|
85
|
+
<A, I, R>(
|
|
86
86
|
self: Schema.Schema<A, I, R>,
|
|
87
87
|
f: (_: I) => Iterable<globalThis.Transferable>
|
|
88
88
|
): Schema.Schema<A, I, R>
|
|
89
|
-
} = dual(2, <
|
|
89
|
+
} = dual(2, <A, I, R>(
|
|
90
90
|
self: Schema.Schema<A, I, R>,
|
|
91
91
|
f: (_: I) => Iterable<globalThis.Transferable>
|
|
92
92
|
) =>
|
package/src/Worker.ts
CHANGED
|
@@ -104,11 +104,11 @@ export declare namespace Worker {
|
|
|
104
104
|
* @category models
|
|
105
105
|
*/
|
|
106
106
|
export interface Options<I> {
|
|
107
|
-
readonly encode?: (message: I) => Effect.Effect<unknown, WorkerError>
|
|
108
|
-
readonly transfers?: (message: I) => ReadonlyArray<unknown>
|
|
109
|
-
readonly
|
|
110
|
-
readonly
|
|
111
|
-
readonly
|
|
107
|
+
readonly encode?: ((message: I) => Effect.Effect<unknown, WorkerError>) | undefined
|
|
108
|
+
readonly transfers?: ((message: I) => ReadonlyArray<unknown>) | undefined
|
|
109
|
+
readonly queue?: WorkerQueue<I> | undefined
|
|
110
|
+
readonly initialMessage?: LazyArg<I> | undefined
|
|
111
|
+
readonly permits?: number | undefined
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -157,17 +157,10 @@ export declare namespace WorkerPool {
|
|
|
157
157
|
* @since 1.0.0
|
|
158
158
|
* @category models
|
|
159
159
|
*/
|
|
160
|
-
export
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
readonly size: number
|
|
165
|
-
} | {
|
|
166
|
-
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
167
|
-
readonly minSize: number
|
|
168
|
-
readonly maxSize: number
|
|
169
|
-
readonly timeToLive: Duration.DurationInput
|
|
170
|
-
})
|
|
160
|
+
export interface Options<I> extends Worker.Options<I> {
|
|
161
|
+
readonly onCreate?: (worker: Worker<I, unknown, unknown>) => Effect.Effect<void, WorkerError>
|
|
162
|
+
readonly size: number
|
|
163
|
+
}
|
|
171
164
|
}
|
|
172
165
|
|
|
173
166
|
/**
|
|
@@ -227,7 +220,7 @@ export const layerManager: Layer.Layer<WorkerManager, never, PlatformWorker> = i
|
|
|
227
220
|
*/
|
|
228
221
|
export const makePool: <I, O, E>(
|
|
229
222
|
options: WorkerPool.Options<I>
|
|
230
|
-
) => Effect.Effect<WorkerPool<I, O, E>,
|
|
223
|
+
) => Effect.Effect<WorkerPool<I, O, E>, WorkerError, WorkerManager | Spawner | Scope.Scope> = internal.makePool
|
|
231
224
|
|
|
232
225
|
/**
|
|
233
226
|
* @since 1.0.0
|
|
@@ -236,7 +229,7 @@ export const makePool: <I, O, E>(
|
|
|
236
229
|
export const makePoolLayer: <Tag, I, O, E>(
|
|
237
230
|
tag: Context.Tag<Tag, WorkerPool<I, O, E>>,
|
|
238
231
|
options: WorkerPool.Options<I>
|
|
239
|
-
) => Layer.Layer<Tag,
|
|
232
|
+
) => Layer.Layer<Tag, WorkerError, WorkerManager | Spawner> = internal.makePoolLayer
|
|
240
233
|
|
|
241
234
|
/**
|
|
242
235
|
* @since 1.0.0
|
|
@@ -277,8 +270,8 @@ export declare namespace SerializedWorker {
|
|
|
277
270
|
* @category models
|
|
278
271
|
*/
|
|
279
272
|
export interface BaseOptions<I> {
|
|
280
|
-
readonly permits?: number
|
|
281
|
-
readonly queue?: WorkerQueue<I>
|
|
273
|
+
readonly permits?: number | undefined
|
|
274
|
+
readonly queue?: WorkerQueue<I> | undefined
|
|
282
275
|
}
|
|
283
276
|
}
|
|
284
277
|
|
|
@@ -341,7 +334,8 @@ export const makeSerialized: <I extends Schema.TaggedRequest.Any>(
|
|
|
341
334
|
*/
|
|
342
335
|
export const makePoolSerialized: <I extends Schema.TaggedRequest.Any>(
|
|
343
336
|
options: SerializedWorkerPool.Options<I>
|
|
344
|
-
) => Effect.Effect<SerializedWorkerPool<I>,
|
|
337
|
+
) => Effect.Effect<SerializedWorkerPool<I>, WorkerError, WorkerManager | Spawner | Scope.Scope> =
|
|
338
|
+
internal.makePoolSerialized
|
|
345
339
|
|
|
346
340
|
/**
|
|
347
341
|
* @since 1.0.0
|
|
@@ -350,7 +344,7 @@ export const makePoolSerialized: <I extends Schema.TaggedRequest.Any>(
|
|
|
350
344
|
export const makePoolSerializedLayer: <Tag, I extends Schema.TaggedRequest.Any>(
|
|
351
345
|
tag: Context.Tag<Tag, SerializedWorkerPool<I>>,
|
|
352
346
|
options: SerializedWorkerPool.Options<I>
|
|
353
|
-
) => Layer.Layer<Tag,
|
|
347
|
+
) => Layer.Layer<Tag, WorkerError, WorkerManager | Spawner> = internal.makePoolSerializedLayer
|
|
354
348
|
|
|
355
349
|
/**
|
|
356
350
|
* @since 1.0.0
|
package/src/WorkerError.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as Schema from "@effect/schema/Schema"
|
|
5
|
-
import * as Cause from "effect/Cause"
|
|
6
|
-
import { identity } from "effect/Function"
|
|
5
|
+
import type * as Cause from "effect/Cause"
|
|
7
6
|
import * as Predicate from "effect/Predicate"
|
|
8
7
|
import * as internal from "./internal/workerError.js"
|
|
9
8
|
|
|
@@ -25,27 +24,13 @@ export type WorkerErrorTypeId = typeof WorkerErrorTypeId
|
|
|
25
24
|
*/
|
|
26
25
|
export const isWorkerError = (u: unknown): u is WorkerError => Predicate.hasProperty(u, WorkerErrorTypeId)
|
|
27
26
|
|
|
28
|
-
const causeDefectPretty: Schema.Schema<unknown> = Schema.transform(
|
|
29
|
-
Schema.Unknown,
|
|
30
|
-
Schema.Unknown,
|
|
31
|
-
{
|
|
32
|
-
decode: identity,
|
|
33
|
-
encode: (defect) => {
|
|
34
|
-
if (Predicate.isObject(defect)) {
|
|
35
|
-
return Cause.pretty(Cause.die(defect))
|
|
36
|
-
}
|
|
37
|
-
return String(defect)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
|
|
42
27
|
/**
|
|
43
28
|
* @since 1.0.0
|
|
44
29
|
* @category errors
|
|
45
30
|
*/
|
|
46
31
|
export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError", {
|
|
47
32
|
reason: Schema.Literal("spawn", "decode", "send", "unknown", "encode"),
|
|
48
|
-
error:
|
|
33
|
+
error: Schema.CauseDefectUnknown
|
|
49
34
|
}) {
|
|
50
35
|
/**
|
|
51
36
|
* @since 1.0.0
|
|
@@ -58,7 +43,7 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
|
|
|
58
43
|
static readonly Cause: Schema.Schema<
|
|
59
44
|
Cause.Cause<WorkerError>,
|
|
60
45
|
Schema.CauseEncoded<WorkerErrorFrom>
|
|
61
|
-
> = Schema.Cause({
|
|
46
|
+
> = Schema.Cause({ error: this })
|
|
62
47
|
|
|
63
48
|
/**
|
|
64
49
|
* @since 1.0.0
|
|
@@ -118,7 +118,7 @@ export const SingleFileSchema: Schema.transform<
|
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
/** @internal */
|
|
121
|
-
export const schemaPersisted = <
|
|
121
|
+
export const schemaPersisted = <A, I extends Partial<Multipart.Persisted>, R>(
|
|
122
122
|
schema: Schema.Schema<A, I, R>,
|
|
123
123
|
options?: ParseOptions | undefined
|
|
124
124
|
) => {
|
|
@@ -112,7 +112,7 @@ export const schemaNoBody = <
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/** @internal */
|
|
115
|
-
export const schemaParams = <
|
|
115
|
+
export const schemaParams = <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
|
|
116
116
|
schema: Schema.Schema<A, I, R>,
|
|
117
117
|
options?: ParseOptions | undefined
|
|
118
118
|
) => {
|
|
@@ -128,7 +128,7 @@ export const schemaParams = <R, I extends Readonly<Record<string, string | Array
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/** @internal */
|
|
131
|
-
export const schemaPathParams = <
|
|
131
|
+
export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, R>(
|
|
132
132
|
schema: Schema.Schema<A, I, R>,
|
|
133
133
|
options?: ParseOptions | undefined
|
|
134
134
|
) => {
|
|
@@ -61,7 +61,7 @@ export const searchParamsFromURL = (url: URL): ReadonlyRecord<string, string | A
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** @internal */
|
|
64
|
-
export const schemaCookies = <
|
|
64
|
+
export const schemaCookies = <A, I extends Readonly<Record<string, string>>, R>(
|
|
65
65
|
schema: Schema.Schema<A, I, R>,
|
|
66
66
|
options?: ParseOptions | undefined
|
|
67
67
|
) => {
|
|
@@ -70,7 +70,7 @@ export const schemaCookies = <R, I extends Readonly<Record<string, string>>, A>(
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/** @internal */
|
|
73
|
-
export const schemaHeaders = <
|
|
73
|
+
export const schemaHeaders = <A, I extends Readonly<Record<string, string>>, R>(
|
|
74
74
|
schema: Schema.Schema<A, I, R>,
|
|
75
75
|
options?: ParseOptions | undefined
|
|
76
76
|
) => {
|
|
@@ -79,7 +79,7 @@ export const schemaHeaders = <R, I extends Readonly<Record<string, string>>, A>(
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/** @internal */
|
|
82
|
-
export const schemaSearchParams = <
|
|
82
|
+
export const schemaSearchParams = <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
|
|
83
83
|
schema: Schema.Schema<A, I, R>,
|
|
84
84
|
options?: ParseOptions | undefined
|
|
85
85
|
) => {
|
|
@@ -97,7 +97,7 @@ const isMultipart = (request: ServerRequest.ServerRequest) =>
|
|
|
97
97
|
request.headers["content-type"]?.toLowerCase().includes("multipart/form-data")
|
|
98
98
|
|
|
99
99
|
/** @internal */
|
|
100
|
-
export const schemaBodyForm = <
|
|
100
|
+
export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, R>(
|
|
101
101
|
schema: Schema.Schema<A, I, R>,
|
|
102
102
|
options?: ParseOptions | undefined
|
|
103
103
|
) => {
|
|
@@ -116,7 +116,7 @@ export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/** @internal */
|
|
119
|
-
export const schemaBodyUrlParams = <
|
|
119
|
+
export const schemaBodyUrlParams = <A, I extends Readonly<Record<string, string>>, R>(
|
|
120
120
|
schema: Schema.Schema<A, I, R>,
|
|
121
121
|
options?: ParseOptions | undefined
|
|
122
122
|
) => {
|
|
@@ -125,7 +125,7 @@ export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/** @internal */
|
|
128
|
-
export const schemaBodyMultipart = <
|
|
128
|
+
export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, R>(
|
|
129
129
|
schema: Schema.Schema<A, I, R>,
|
|
130
130
|
options?: ParseOptions | undefined
|
|
131
131
|
) => {
|
|
@@ -71,7 +71,7 @@ export const SchemaStoreTypeId: KeyValueStore.SchemaStoreTypeId = Symbol.for(
|
|
|
71
71
|
const makeSchemaStore = <A, I, R>(
|
|
72
72
|
store: KeyValueStore.KeyValueStore,
|
|
73
73
|
schema: Schema.Schema<A, I, R>
|
|
74
|
-
): KeyValueStore.SchemaStore<
|
|
74
|
+
): KeyValueStore.SchemaStore<A, R> => {
|
|
75
75
|
const jsonSchema = Schema.parseJson(schema)
|
|
76
76
|
const parse = Schema.decodeUnknown(jsonSchema)
|
|
77
77
|
const encode = Schema.encode(jsonSchema)
|
|
@@ -170,7 +170,7 @@ export const layerSchema = <A, I, R>(
|
|
|
170
170
|
schema: Schema.Schema<A, I, R>,
|
|
171
171
|
tagIdentifier: string
|
|
172
172
|
) => {
|
|
173
|
-
const tag = Context.GenericTag<KeyValueStore.SchemaStore<
|
|
173
|
+
const tag = Context.GenericTag<KeyValueStore.SchemaStore<A, R>>(tagIdentifier)
|
|
174
174
|
const layer = Layer.effect(tag, Effect.map(keyValueStoreTag, (store) => store.forSchema(schema)))
|
|
175
175
|
return { tag, layer } as const
|
|
176
176
|
}
|
package/src/internal/worker.ts
CHANGED
|
@@ -75,7 +75,7 @@ export const makeManager = Effect.gen(function*() {
|
|
|
75
75
|
const spawn = yield* _(Spawner)
|
|
76
76
|
const id = idCounter++
|
|
77
77
|
let requestIdCounter = 0
|
|
78
|
-
const semaphore =
|
|
78
|
+
const semaphore = Effect.unsafeMakeSemaphore(permits)
|
|
79
79
|
const requestMap = new Map<
|
|
80
80
|
number,
|
|
81
81
|
readonly [Queue.Queue<Exit.Exit<ReadonlyArray<O>, E | WorkerError>>, Deferred.Deferred<void>]
|
|
@@ -238,7 +238,7 @@ export const makeManager = Effect.gen(function*() {
|
|
|
238
238
|
)
|
|
239
239
|
|
|
240
240
|
yield* semaphore.take(1).pipe(
|
|
241
|
-
Effect.
|
|
241
|
+
Effect.andThen(outbound.take),
|
|
242
242
|
Effect.flatMap(([id, request, span]) =>
|
|
243
243
|
pipe(
|
|
244
244
|
Effect.suspend(() => {
|
|
@@ -299,17 +299,11 @@ export const makePool = <I, O, E>(
|
|
|
299
299
|
Effect.tap((worker) => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))),
|
|
300
300
|
options.onCreate ? Effect.tap(options.onCreate) : identity
|
|
301
301
|
)
|
|
302
|
-
const backing = yield*
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
timeToLive: options.timeToLive
|
|
308
|
-
}) :
|
|
309
|
-
Pool.make({
|
|
310
|
-
acquire,
|
|
311
|
-
size: options.size
|
|
312
|
-
})
|
|
302
|
+
const backing = yield* Pool.make({
|
|
303
|
+
acquire,
|
|
304
|
+
size: options.size
|
|
305
|
+
})
|
|
306
|
+
const get = Effect.scoped(backing.get)
|
|
313
307
|
const pool: Worker.WorkerPool<I, O, E> = {
|
|
314
308
|
backing,
|
|
315
309
|
broadcast: (message: I) =>
|
|
@@ -317,20 +311,13 @@ export const makePool = <I, O, E>(
|
|
|
317
311
|
concurrency: "unbounded",
|
|
318
312
|
discard: true
|
|
319
313
|
}),
|
|
320
|
-
execute: (message: I) =>
|
|
321
|
-
|
|
322
|
-
Effect.map(
|
|
323
|
-
Effect.scoped(backing.get),
|
|
324
|
-
(worker) => worker.execute(message)
|
|
325
|
-
)
|
|
326
|
-
),
|
|
327
|
-
executeEffect: (message: I) =>
|
|
328
|
-
Effect.flatMap(
|
|
329
|
-
Effect.scoped(backing.get),
|
|
330
|
-
(worker) => worker.executeEffect(message)
|
|
331
|
-
)
|
|
314
|
+
execute: (message: I) => Stream.unwrap(Effect.map(get, (worker) => worker.execute(message))),
|
|
315
|
+
executeEffect: (message: I) => Effect.flatMap(get, (worker) => worker.executeEffect(message))
|
|
332
316
|
}
|
|
333
317
|
|
|
318
|
+
// report any spawn errors
|
|
319
|
+
yield* get
|
|
320
|
+
|
|
334
321
|
return pool
|
|
335
322
|
})
|
|
336
323
|
|
|
@@ -410,6 +397,7 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
|
|
|
410
397
|
acquire,
|
|
411
398
|
size: options.size
|
|
412
399
|
})
|
|
400
|
+
const get = Effect.scoped(backing.get)
|
|
413
401
|
const pool: Worker.SerializedWorkerPool<I> = {
|
|
414
402
|
backing,
|
|
415
403
|
broadcast: <Req extends I>(message: Req) =>
|
|
@@ -418,19 +406,14 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
|
|
|
418
406
|
discard: true
|
|
419
407
|
}) as any,
|
|
420
408
|
execute: <Req extends I>(message: Req) =>
|
|
421
|
-
Stream.unwrap(
|
|
422
|
-
Effect.map(
|
|
423
|
-
Effect.scoped(backing.get),
|
|
424
|
-
(worker) => worker.execute(message)
|
|
425
|
-
)
|
|
426
|
-
) as any,
|
|
409
|
+
Stream.unwrap(Effect.map(get, (worker) => worker.execute(message))) as any,
|
|
427
410
|
executeEffect: <Req extends I>(message: Req) =>
|
|
428
|
-
Effect.flatMap(
|
|
429
|
-
Effect.scoped(backing.get),
|
|
430
|
-
(worker) => worker.executeEffect(message)
|
|
431
|
-
) as any
|
|
411
|
+
Effect.flatMap(get, (worker) => worker.executeEffect(message)) as any
|
|
432
412
|
}
|
|
433
413
|
|
|
414
|
+
// report any spawn errors
|
|
415
|
+
yield* get
|
|
416
|
+
|
|
434
417
|
return pool
|
|
435
418
|
})
|
|
436
419
|
|