MCPcopy
hub / github.com/Effect-TS/effect / makeQueue

Function makeQueue

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

Source from the content-addressed store, hash-verified

74}
75
76const makeQueue = (
77 options:
78 | PositionOptions & {
79 readonly bufferSize?: number | undefined
80 }
81 | undefined
82) =>
83 Queue.sliding<Either.Either<GeolocationPosition, GeolocationError>>(options?.bufferSize ?? 16).pipe(
84 Effect.tap((queue) =>
85 Effect.acquireRelease(
86 Effect.sync(() =>
87 navigator.geolocation.watchPosition(
88 (position) => queue.unsafeOffer(Either.right(position)),
89 (cause) => {
90 if (cause.code === cause.PERMISSION_DENIED) {
91 queue.unsafeOffer(Either.left(new GeolocationError({ reason: "PermissionDenied", cause })))
92 } else if (cause.code === cause.TIMEOUT) {
93 queue.unsafeOffer(Either.left(new GeolocationError({ reason: "Timeout", cause })))
94 }
95 },
96 options
97 )
98 ),
99 (handleId) => Effect.sync(() => navigator.geolocation.clearWatch(handleId))
100 )
101 )
102 )
103
104/**
105 * @since 1.0.0

Callers 5

Geolocation.tsFile · 0.85
boundedFunction · 0.85
droppingFunction · 0.85
slidingFunction · 0.85
unboundedFunction · 0.85

Calls 3

syncMethod · 0.80
pipeMethod · 0.65
unsafeOfferMethod · 0.65

Tested by

no test coverage detected