Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .swm/rate-limit-queue-overview.3c009.sw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
id: 3c009
name: Rate Limit Queue Overview
file_version: 1.0.2
app_version: 0.8.9-2
file_blobs:
src/queue.ts: e2a367fa5404b54e6bca8160935165f1f6d3ba5c
package.json: 4790390936c7adcc4a21829b599e08a46798e597
tsconfig.json: ced946be08b6157720abbd71e4da1a716bf00c1f
---

The rate limit queue can be used to queue & distribute API calls evenly over a given time frame in order to avoid getting rate limited.

<br/>

All code can be found in the source directory: `📄 src`

<br/>

Most of the work happens in the constructor of the queue where all initialisation is kicked off. This will trigger as soon as a Queue is instantiated.
<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->
### 📄 src/queue.ts
```typescript
⬜ 18 constructor(onProcess: WorkerFunction<T>, items: T[], dailyRateLimit: number, sourceQueueOnEveryRun = false) {
⬜ 19 this.queue = items;
⬜ 20 this.snapshot = items;
🟩 21 this.onProcess = onProcess;
🟩 22 this.sourceQueueOnEveryRun = sourceQueueOnEveryRun;
🟩 23 this.dailyRateLimit = dailyRateLimit;
🟩 24 this.start();
⬜ 25 }
⬜ 26
⬜ 27 private start = () => {
```

<br/>

## Adding Tests

<br/>

You can add tests to the `📄 src` folder. Make sure to suffix them with \`\*.test.ts\`.

<br/>

## Important Bits

<br/>

All code is packaged from lib. Make sure you build the package first before distributing it.
<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->
### 📄 package.json
```json
⬜ 17 "typescript": "^4.3.4"
⬜ 18 },
⬜ 19 "files": [
🟩 20 "lib/**/*"
⬜ 21 ]
⬜ 22 }
⬜ 23
```

<br/>

The output folder is set up in the tsconfig file
<!-- NOTE-swimm-snippet: the lines below link your snippet to Swimm -->
### 📄 tsconfig.json
```json
⬜ 14 // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
⬜ 15 // "sourceMap": true, /* Generates corresponding '.map' file. */
⬜ 16 // "outFile": "./", /* Concatenate and emit output to single file. */
🟩 17 "outDir": "./lib", /* Redirect output structure to the directory. */
⬜ 18 // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
⬜ 19 // "composite": true, /* Enable project compilation */
⬜ 20 // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
```

<br/>

This file was generated by Swimm. [Click here to view it in the app](https://app.swimm.io/repos/Z2l0aHViJTNBJTNBcmF0ZS1saW1pdC1xdWV1ZSUzQSUzQUZyZWRkaXh4/docs/3c009).
6 changes: 6 additions & 0 deletions .swm/swimm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"repo_id": "Z2l0aHViJTNBJTNBcmF0ZS1saW1pdC1xdWV1ZSUzQSUzQUZyZWRkaXh4",
"configuration": {
"swmd": true
}
}