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

Function makeQueue

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

Source from the content-addressed store, hash-verified

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

Callers 1

Geolocation.tsFile · 0.85

Calls 4

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

Tested by

no test coverage detected