-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add taskQueue to handle each request one by one #862
Conversation
WalkthroughThe changes introduce a task queue and processing flag to the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TaskQueue as taskQueue
participant ProcessingFlag as processing
Client->>TaskQueue: enqueueTask(task)
Note over TaskQueue: Add task to queue
TaskQueue->>ProcessingFlag: Check if processing
ProcessingFlag-->>TaskQueue: No
TaskQueue->>Client: processQueue
loop Process tasks
Client->>TaskQueue: Dequeue and execute task
TaskQueue->>ProcessingFlag: Set processing to true
TaskQueue->>TaskQueue: Execute next task
end
TaskQueue->>ProcessingFlag: Set processing to false
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #862 +/- ##
==========================================
+ Coverage 80.84% 80.89% +0.04%
==========================================
Files 60 60
Lines 4578 4600 +22
Branches 934 936 +2
==========================================
+ Hits 3701 3721 +20
- Misses 608 610 +2
Partials 269 269 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
src/client/client.ts (1)
166-167
: Add type annotation fortaskQueue
.To enhance readability and maintainability, consider adding a type annotation for the
taskQueue
property.- private taskQueue: Array<() => Promise<any>>; + private taskQueue: Array<() => Promise<void>>;
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/client/client.ts (11 hunks)
- test/integration/client_test.ts (2 hunks)
Additional comments not posted (9)
src/client/client.ts (8)
242-262
: Ensure proper error handling indeactivate
.The
deactivate
method uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.
486-507
: Ensure proper error handling inremove
.The
remove
method uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.Verification successful
Let's update the script to search for
remove(
method calls in JavaScript and TypeScript files to ensure proper error handling.
Proper error handling in
remove
method is verified.The integration tests in
test/integration/document_test.ts
includeassertThrowsAsync
calls around theremove
method, indicating that error handling is being tested and managed appropriately.
test/integration/document_test.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all calls to `remove` handle potential errors. # Test: Search for `remove` method calls. Expect: Proper error handling. rg --type javascript 'remove\(' --context 3Length of output: 80
Script:
#!/bin/bash # Description: Verify that all calls to `remove` handle potential errors. # Test: Search for `remove` method calls in JavaScript and TypeScript files. Expect: Proper error handling. rg 'remove\(' --type js --type ts --context 3Length of output: 18565
453-464
: Ensure proper error handling insync
for a single document.The
sync
method for a single document uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.
760-775
: EnsureprocessNext
handles rejections properly.The
processNext
method processes tasks sequentially. Ensure that tasks handle rejections properly to avoid unhandled promise rejections.Verification successful
Verification successful:
processNext
handles rejections properly.The
enqueueTask
method ensures that tasks enqueued in thetaskQueue
handle rejections by catching errors and invoking thereject
function. This confirms that theprocessNext
method will process tasks with proper error handling.
src/client/client.ts
:enqueueTask
method handles task rejections.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that tasks processed by `processNext` handle rejections properly. # Test: Search for `processNext` method calls. Expect: Proper error handling. rg --type javascript 'processNext\(' --context 3Length of output: 85
Script:
#!/bin/bash # Description: Verify that tasks processed by `processNext` handle rejections properly. # Test: Search for `processNext` method calls in JavaScript and TypeScript files. Expect: Proper error handling. rg 'processNext\(' --glob '*.js' --glob '*.ts' --context 3Length of output: 977
Script:
#!/bin/bash # Description: Verify that tasks enqueued in taskQueue handle rejections properly. # Test: Search for task enqueueing in `src/client/client.ts` and check for proper error handling. rg 'this.taskQueue.push' --glob 'src/client/client.ts' --context 5Length of output: 623
356-382
: Ensure proper error handling indetach
.The
detach
method uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.
289-327
: Ensure proper error handling inattach
.The
attach
method uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.Verification successful
No issues found with error handling in the
attach
method usage.The
attach
method is not called in the main application logic files, excluding tests and examples. Therefore, the existing error handling within theattach
method itself is sufficient for its current usage.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all calls to `attach` handle potential errors. # Test: Search for `attach` method calls. Expect: Proper error handling. rg --type javascript 'attach\(' --context 3Length of output: 80
Script:
#!/bin/bash # Description: Verify that all calls to `attach` handle potential errors. # Test: Search for `attach` method calls. Expect: Proper error handling. rg --type ts 'attach\(' --context 3Length of output: 49832
Script:
#!/bin/bash # Description: Verify that all calls to `attach` handle potential errors in the main application logic. # Test: Search for `attach` method calls in the main application files, excluding test files. rg --type ts 'attach\(' --context 3 --glob '!test/*'Length of output: 2473
Script:
#!/bin/bash # Description: Verify that all calls to `attach` handle potential errors in the main application logic, excluding test and example files. # Test: Search for `attach` method calls in the main application files, excluding test and example files. rg --type ts 'attach\(' --context 3 --glob '!test/*' --glob '!examples/*'Length of output: 75
743-754
: EnsureenqueueTask
handles rejections properly.The
enqueueTask
method pushes tasks to the queue and starts processing if not already processing. Ensure that the tasks handle rejections properly.
214-231
: Ensure proper error handling inactivate
.The
activate
method uses.catch
to log errors and rethrow them. Ensure that the caller of this method handles these errors appropriately.test/integration/client_test.ts (1)
752-765
: Good test case for sequential request handling!The test case effectively verifies that each request is handled sequentially by creating multiple clients and documents, and ensuring they are processed one by one.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/client/client.ts (11 hunks)
- test/integration/client_test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/client/client.ts
- test/integration/client_test.ts
What this PR does / why we need it?
Add taskQueue to handle each request one by one
When using JS SDK in environments like React, it is possible to assign Client to React Components. However, when Component Unmount is executed by moving location, resources like
yorkie.Client
need to bedeactivated
oryorkie.Document
need to bedetached
. The challenge arises when it is not possible to await asynchronous requests while deactivating one by one due to some reasons.To address this issue, this commit introduces a task queue in
Client
to handle all requests one by one, ensuring proper deactivation or detachment.Any background context you want to provide?
What are the relevant tickets?
Addresses yorkie-team/codepair#220
Checklist
Summary by CodeRabbit
New Features
Tests
Client
class.