-
Notifications
You must be signed in to change notification settings - Fork 0
[ECO-5260] feat: initial local proxy implementation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
|
||
- name: Run test | ||
run: npm run test |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
import { CompletableDeferred } from './completable-deferred'; | ||||||
|
||||||
type AsyncTask = () => Promise<void>; | ||||||
|
||||||
export class AsyncQueue { | ||||||
private readonly queue: AsyncTask[] = []; | ||||||
private processing: boolean = false; | ||||||
|
||||||
enqueue(task: AsyncTask): Promise<void> { | ||||||
const deferredValue = CompletableDeferred<void>(); | ||||||
this.queue.push(async () => { | ||||||
try { | ||||||
await task(); | ||||||
} finally { | ||||||
deferredValue.complete(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're not catching an error here and I believe it will lead to undandled promise rejections at the line below where we call |
||||||
} | ||||||
}); | ||||||
this.processNext(); | ||||||
return deferredValue.get() | ||||||
} | ||||||
|
||||||
private async processNext() { | ||||||
if (this.processing || this.queue.length === 0) return; | ||||||
|
||||||
this.processing = true; | ||||||
|
||||||
const task = this.queue.shift(); | ||||||
|
||||||
try { | ||||||
await task!!(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
should it be just one exclamation mark? |
||||||
} finally { | ||||||
this.processing = false; | ||||||
this.processNext(); | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
type CompletionHandler<T = void> = (value: T) => void | ||
|
||
class DefaultCompletableDeferred<T = void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would like to have a description for this primitive as it's not immediately obvious what it does. |
||
private _completeWith!: CompletionHandler<T>; | ||
private value: T | undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it look like |
||
|
||
private valuePromise = new Promise<T>(resolve => { | ||
this._completeWith = resolve; | ||
}); | ||
|
||
public complete(value: T): void { | ||
this._completeWith(value); | ||
} | ||
|
||
public async get(): Promise<T> { | ||
return this.value ?? this.valuePromise; | ||
} | ||
} | ||
|
||
export function CompletableDeferred<T>() { | ||
return new DefaultCompletableDeferred<T>() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './proxy.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pauseConnection
is not in the InterceptingProxy interface. should it bepauseAllConnections
?that being said we should still have a way to pause connection by an id. wdyt?