MCPcopy Create free account
hub / github.com/effect-app/libs / tryAcquire

Function tryAcquire

packages/infra/src/ClusterCosmos.ts:920–936  ·  view source on GitHub ↗
(address: string, shardId: string, now: number)

Source from the content-addressed store, hash-verified

918 )
919
920 const tryAcquire = (address: string, shardId: string, now: number) =>
921 readLock(shardId).pipe(
922 Effect.flatMap((lock) =>
923 Option.match(lock, {
924 onNone: () => createLock(address, shardId, now),
925 onSome: (doc) => {
926 if (doc.address !== address && now - doc.acquiredAt <= expires) {
927 return Effect.succeed(false)
928 }
929 doc.address = address
930 doc.acquiredAt = now
931 return writeLock(doc)
932 }
933 })
934 ),
935 Effect.map((acquired) => acquired ? Option.some(shardId) : Option.none())
936 )
937
938 return RunnerStorage.makeEncoded({
939 getRunners: Effect.sync(() => Date.now()).pipe(

Callers 1

ClusterCosmos.tsFile · 0.70

Calls 7

createLockFunction · 0.85
someMethod · 0.80
readLockFunction · 0.70
writeLockFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…