MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeQueue

Function makeQueue

packages/platform/browser/src/Geolocation.ts:162–199  ·  view source on GitHub ↗
(
  options:
    | PositionOptions & {
      readonly bufferSize?: number | undefined
    }
    | undefined
)

Source from the content-addressed store, hash-verified

160export type GeolocationErrorReason = PositionUnavailable | PermissionDenied | Timeout
161
162const makeQueue = (
163 options:
164 | PositionOptions & {
165 readonly bufferSize?: number | undefined
166 }
167 | undefined
168) =>
169 Queue.sliding<GeolocationPosition, GeolocationError>(options?.bufferSize ?? 16).pipe(
170 Effect.tap((queue) =>
171 Effect.acquireRelease(
172 Effect.sync(() =>
173 navigator.geolocation.watchPosition(
174 (position) => Queue.offerUnsafe(queue, position),
175 (cause) => {
176 if (cause.code === cause.PERMISSION_DENIED) {
177 const error = new GeolocationError({
178 reason: new PermissionDenied({ cause })
179 })
180 Queue.failCauseUnsafe(queue, Cause.fail(error))
181 } else if (cause.code === cause.TIMEOUT) {
182 const error = new GeolocationError({
183 reason: new Timeout({ cause })
184 })
185 Queue.failCauseUnsafe(queue, Cause.fail(error))
186 } else if (cause.code === cause.POSITION_UNAVAILABLE) {
187 const error = new GeolocationError({
188 reason: new PositionUnavailable({ cause })
189 })
190 Queue.failCauseUnsafe(queue, Cause.fail(error))
191 }
192 },
193 options
194 )
195 ),
196 (handleId) => Effect.sync(() => navigator.geolocation.clearWatch(handleId))
197 )
198 )
199 )
200
201/**
202 * Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.

Callers 3

Geolocation.tsFile · 0.70
suiteWithFunction · 0.50
makeOwnershipQueueFunction · 0.50

Calls 4

offerUnsafeMethod · 0.80
pipeMethod · 0.65
failMethod · 0.65
syncMethod · 0.45

Tested by

no test coverage detected