Skip to content

Commit a2e5538

Browse files
committed
wip
1 parent a163571 commit a2e5538

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

packages/cluster/src/Sharding.ts

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,46 +1211,45 @@ const make = Effect.gen(function*() {
12111211
const reaper = yield* EntityReaper
12121212
const entityManagerLatches = new Map<string, Effect.Latch>()
12131213

1214-
const registerEntity: Sharding["Type"]["registerEntity"] = Effect.fnUntraced(
1215-
function*(entity, build, options) {
1216-
if (Option.isNone(config.runnerAddress) || entityManagers.has(entity.type)) return
1217-
const scope = yield* Scope.make()
1218-
yield* Scope.addFinalizer(
1219-
scope,
1220-
Effect.sync(() => {
1221-
state.closed = true
1222-
})
1223-
)
1224-
const manager = yield* EntityManager.make(entity, build, {
1225-
...options,
1226-
storage,
1227-
runnerAddress: config.runnerAddress.value,
1228-
sharding
1229-
}).pipe(
1230-
Effect.provide(context.pipe(
1231-
Context.add(EntityReaper, reaper),
1232-
Context.add(Scope.Scope, scope),
1233-
Context.add(Snowflake.Generator, snowflakeGen)
1234-
))
1235-
) as Effect.Effect<EntityManager.EntityManager>
1236-
const state: EntityManagerState = {
1237-
entity,
1238-
scope,
1239-
closed: false,
1240-
manager
1241-
}
1242-
entityManagers.set(entity.type, state)
1243-
if (entityManagerLatches.has(entity.type)) {
1244-
entityManagerLatches.get(entity.type)!.unsafeOpen()
1245-
entityManagerLatches.delete(entity.type)
1246-
}
1214+
const registerEntity: Sharding["Type"]["registerEntity"] = Effect.fnUntraced(function*(
1215+
entity,
1216+
build,
1217+
options
1218+
) {
1219+
if (Option.isNone(config.runnerAddress) || entityManagers.has(entity.type)) return
1220+
const scope = yield* Scope.make()
1221+
yield* Scope.addFinalizer(
1222+
scope,
1223+
Effect.sync(() => {
1224+
state.closed = true
1225+
})
1226+
)
1227+
const manager = yield* EntityManager.make(entity, build, {
1228+
...options,
1229+
storage,
1230+
runnerAddress: config.runnerAddress.value,
1231+
sharding
1232+
}).pipe(
1233+
Effect.provide(context.pipe(
1234+
Context.add(EntityReaper, reaper),
1235+
Context.add(Scope.Scope, scope),
1236+
Context.add(Snowflake.Generator, snowflakeGen)
1237+
))
1238+
) as Effect.Effect<EntityManager.EntityManager>
1239+
const state: EntityManagerState = {
1240+
entity,
1241+
scope,
1242+
closed: false,
1243+
manager
1244+
}
1245+
entityManagers.set(entity.type, state)
1246+
if (entityManagerLatches.has(entity.type)) {
1247+
entityManagerLatches.get(entity.type)!.unsafeOpen()
1248+
entityManagerLatches.delete(entity.type)
1249+
}
12471250

1248-
yield* PubSub.publish(events, EntityRegistered({ entity }))
1249-
},
1250-
// register entities while storage is idle
1251-
// this ensures message order is preserved
1252-
withStorageReadLock
1253-
)
1251+
yield* PubSub.publish(events, EntityRegistered({ entity }))
1252+
})
12541253

12551254
yield* Scope.addFinalizerExit(
12561255
shardingScope,

0 commit comments

Comments
 (0)