How lacti/typescript-webworker-rpc works
Main Components
a) Client-Side Components:
• RPCClient Module
• Methods: call(), post(), onError()
• Window Context
b) Server-Side Components:
• RPCServer Module
• Methods: on(), onError()
• Web Worker Context
c) Communication Layer:
• Message Channel
• Transfer Objects
Relationship Flows
• Client to Server: postMessage flow
• Server to Client: response flow
• Error handling paths (in red)
• Transfer objects flow (for ArrayBuffer transfers)
Specific Implementation Details
Technical elements:
• TypeScript interfaces (show as small interface definitions)
• Promise handling layer
• Message queue system
• Transfer object handling
• Window | | Web Worker |
• postMessage | +----------+ |
• RPCClient |<-|------------------>|->|RPCServer | |
Additional Elements
Supporting components:
• Error handling flow paths
• Transfer object specifications
Implementation Notes
Annotations for:
• TypeScript type safety
• Promise-based communication
• Transferable object handling
• Fire-and-forget operations (post method)
Key Considerations:
Type System
• How TypeScript interfaces ensure type safety
• Generic type parameters in the design
Communication Patterns
• Both synchronous (call) and asynchronous (post) patterns
• Error propagation paths
Special Features
• ArrayBuffer transfer capabilities
• Duplex communication support
• The clean separation between client and server components
• Type-safe communication channels
• Bidirectional messaging capabilities
• Error handling paths
• Support for transferable objects