fix(api): remove redundant typingHandlerLock and spinlock loop - #1359
Open
jhalak101205-cpu wants to merge 1 commit into
Open
fix(api): remove redundant typingHandlerLock and spinlock loop#1359jhalak101205-cpu wants to merge 1 commit into
jhalak101205-cpu wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey @Aryan-Verma-999, here is the Pull Request for the issue. Please review it and let me know if you have any feedback!
Summary
Removes the global
typingHandlerLockvariable, fallbacksetTimeout, and synchronouswhile (typingHandlerLock) {}spinlock loop frompackages/api/src/EmbeddedChatApi.ts.Context & Issue
Fixes #1354.
Logic & Implementation Details
Leveraging Event-Loop Task Queue Semantics:
In single-threaded JavaScript, incoming WebSocket events are queued and processed sequentially off the Event Loop. Synchronous function execution is atomic and completes without thread context switching. Therefore, mutex spinlocks like
while (lock) {}are redundant and pose a deadlock risk if the lock remains set.Atomic Array Management:
handleTypingEventnow directly and safely performs atomic array updates:indexOfandspliceto clear existing instances of the user fromthis.typingUsers.unshiftto prepend the active typing user to the front of the list.Clean Subscriber Broadcasting:
Creates an immutable copy via
cloneArray(this.typingUsers)and broadcasts the updated status array to allonTypingStatusCallbackslisteners.Verification
http://localhost:5173/&http://localhost:6006/).yarn build.