Files
Denis Bykhov da88233dda Add 'foundations/net/' from commit '7722c9534141cf92ea7e990b8687c14ef3c747b2'
git-subtree-dir: foundations/net
git-subtree-mainline: 2b0d510202
git-subtree-split: 7722c95341
2025-11-26 22:57:00 +05:00

47 lines
1.7 KiB
TypeScript

/**
* Example: Using custom timeout for BackRPC client
*
* This example demonstrates how to create a network client with custom timeout values.
*
* @example
* // Start the network server first:
* // cd pods/network-pod && rushx dev
*
* // Then run this example:
* // cd examples && rushx run:timeout
*/
import { createNetworkClient } from '@hcengineering/network-client'
async function main() {
console.log('=== Custom Timeout Example ===\n')
// Example 1: Default behavior - uses environment-based timeout
// In development (NODE_ENV=development): 3600 seconds (1 hour)
// In production: 3 seconds
await using defaultClient = createNetworkClient('localhost:3737')
console.log('✓ Created client with default timeout')
// Example 2: Custom timeout - 10 minutes (600 seconds)
await using customTimeoutClient = createNetworkClient('localhost:3737', 600)
console.log('✓ Created client with 600s timeout')
// Example 3: Short timeout for fast failure detection - 1 second
await using fastFailClient = createNetworkClient('localhost:3737', 1)
console.log('✓ Created client with 1s timeout')
// Example 4: Very long timeout for debugging - 2 hours (7200 seconds)
await using debugClient = createNetworkClient('localhost:3737', 7200)
console.log('✓ Created client with 7200s timeout')
console.log('\n✓ All clients created successfully!')
console.log('Note: These are timeout settings for detecting inactive clients')
console.log('Server will mark a client as dead after [aliveTimeout] seconds of inactivity')
// Exit cleanly
await new Promise(resolve => setTimeout(resolve, 100))
process.exit(0)
}
main().catch(console.error)