11import type * as Cause from "../Cause.js"
2- import type { Clock } from "../Clock.js"
32import * as Context from "../Context.js"
43import type * as Deferred from "../Deferred.js"
54import * as Duration from "../Duration.js"
@@ -139,7 +138,6 @@ const getImpl = core.fnUntraced(function*<K, A, E>(self: RcMapImpl<K, A, E>, key
139138 if ( o . _tag === "Some" ) {
140139 entry = o . value
141140 entry . refCount ++
142- if ( entry . fiber ) yield * core . interruptFiber ( entry . fiber )
143141 } else if ( Number . isFinite ( self . capacity ) && MutableHashMap . size ( self . state . map ) >= self . capacity ) {
144142 return yield * core . fail (
145143 new core . ExceededCapacityException ( `RcMap attempted to exceed capacity of ${ self . capacity } ` )
@@ -197,17 +195,18 @@ const release = <K, A, E>(self: RcMapImpl<K, A, E>, key: K, entry: State.Entry<A
197195 }
198196
199197 entry . expiresAt = clock . unsafeCurrentTimeMillis ( ) + Duration . toMillis ( self . idleTimeToLive )
198+ if ( entry . fiber ) return core . void
200199
201- return clock . sleep ( self . idleTimeToLive ) . pipe (
202- core . zipRight ( waitUntilExpired ( entry , clock ) ) ,
203- core . interruptible ,
204- core . zipRight ( core . suspend ( ( ) => {
205- if ( self . state . _tag === "Open" && entry . refCount === 0 ) {
206- MutableHashMap . remove ( self . state . map , key )
207- return core . scopeClose ( entry . scope , core . exitVoid )
208- }
209- return core . void
210- } ) ) ,
200+ return core . interruptibleMask ( function loop ( restore ) : Effect < void > {
201+ const now = clock . unsafeCurrentTimeMillis ( )
202+ const remaining = entry . expiresAt - now
203+ if ( remaining <= 0 ) {
204+ if ( self . state . _tag === "Closed" || entry . refCount > 0 ) return core . void
205+ MutableHashMap . remove ( self . state . map , key )
206+ return restore ( core . scopeClose ( entry . scope , core . exitVoid ) )
207+ }
208+ return core . flatMap ( clock . sleep ( Duration . millis ( remaining ) ) , ( ) => loop ( restore ) )
209+ } ) . pipe (
211210 fiberRuntime . ensuring ( core . sync ( ( ) => {
212211 entry . fiber = undefined
213212 } ) ) ,
@@ -219,16 +218,6 @@ const release = <K, A, E>(self: RcMapImpl<K, A, E>, key: K, entry: State.Entry<A
219218 )
220219 } )
221220
222- const waitUntilExpired = < A , E > ( entry : State . Entry < A , E > , clock : Clock ) =>
223- core . suspend ( function loop ( ) : Effect < void > {
224- const now = clock . unsafeCurrentTimeMillis ( )
225- const remaining = entry . expiresAt - now
226- if ( remaining <= 0 ) {
227- return core . void
228- }
229- return core . flatMap ( clock . sleep ( Duration . millis ( remaining ) ) , loop )
230- } )
231-
232221/** @internal */
233222export const keys = < K , A , E > ( self : RcMap . RcMap < K , A , E > ) : Effect < Array < K > > => {
234223 const impl = self as RcMapImpl < K , A , E >
0 commit comments