Live-Mutex currently provides two broker implementations:
Broker(frombroker.ts) - Original implementationBroker1(frombroker-1.ts) - Current recommended implementation
Broker1 is the recommended and actively maintained broker implementation.
Broker1is used by the main codebase and all current tests- Both implementations have been updated with the same bug fixes
Brokeris maintained for backward compatibility but may be deprecated in the future
Both brokers provide identical functionality:
- Basic lock/unlock operations
- Read-Write (RW) lock support
- Unix Domain Socket (UDS) support
- Version checking
- Inspect and listing commands
- Same configuration options
The implementations are nearly identical, with Broker1 being the more recent version. Both have:
- Same bug fixes applied (double-counting readers, release callbacks, etc.)
- Same API surface
- Same performance characteristics
- Same configuration options
Before:
import {Broker} from 'live-mutex';After:
import {Broker1} from 'live-mutex';
// Or use the alias
import {Broker1 as Broker} from 'live-mutex';Before:
const broker = new Broker({port: 6970, host: 'localhost'});After:
const broker = new Broker1({port: 6970, host: 'localhost'});If you have TypeScript type annotations:
Before:
function createBroker(): Broker {
return new Broker();
}After:
import {Broker1} from 'live-mutex';
function createBroker(): Broker1 {
return new Broker1();
}After migrating, thoroughly test your application:
# Run your test suite
npm test
# Test broker functionality
lmx-quick-start test
# Test RW locks
lmx-test rw- Both
BrokerandBroker1are exported from the main module - Both are fully functional and tested
- Clients work with either broker implementation
- No breaking API changes between the two
Broker1will continue to be the primary implementationBrokermay be deprecated in a future major version- Migration path will be provided with advance notice
The two implementations exist due to:
- Historical reasons:
Brokerwas the original implementation - Refactoring:
Broker1was created during a refactoring effort - Testing: Both are maintained to ensure compatibility
- Gradual migration: Allows users to migrate at their own pace
Use Broker1 - It's the recommended implementation for all new projects:
import {Broker1, Client} from 'live-mutex';
const broker = new Broker1({port: 6970});
await broker.ensure();- If using
Broker: Consider migrating toBroker1when convenient - If using
Broker1: Continue using it - no action needed - If unsure: Check your imports - if you see
Broker1, you're already using the recommended version
The CLI tools use Broker1 by default:
lmx-quick-start start # Uses Broker1 internally
lmx start # Uses Broker1 internallyIf you want to test both implementations:
import {Broker, Broker1} from 'live-mutex';
// Test with Broker
const broker1 = new Broker({port: 6970});
await broker1.ensure();
// Test with Broker1
const broker2 = new Broker1({port: 6971});
await broker2.ensure();A: No. Both implementations are fully functional. Migrate when convenient.
A: Not in the immediate future. Any deprecation will be announced well in advance.
A: No significant performance differences. Both implementations have similar performance characteristics.
A: Yes. Clients are compatible with both Broker and Broker1.
A: Use Broker1 for new deployments. If you're already using Broker and it's working, you can continue using it.
If you encounter issues during migration:
- Check the main README for usage examples
- Review readme-2.md for detailed usage guide
- Run tests:
lmx-quick-start test - Check broker status:
lmx status
- Current recommendation: Use
Broker1 - Migration: Simple import change
- Compatibility: Both work identically
- Future:
Broker1is the long-term solution