(
options:
| PositionOptions & {
readonly bufferSize?: number | undefined
}
| undefined
)
| 152 | export type GeolocationErrorReason = PositionUnavailable | PermissionDenied | Timeout |
| 153 | |
| 154 | const 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. |
no test coverage detected