semaphore
1.0.1, released 9 months ago by an unverified publisher
Lightweight semaphore, condition variable, and lock implementation for isolates.
What it does
Provides synchronization primitives like semaphores, condition variables, and locks to control access to shared resources within an isolate. Helps coordinate asynchronous producer-consumer workloads or limit simultaneous tasks.
AI-written summary of version 1.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to limit concurrent access to a shared resource within an isolate
- You require traditional concurrency primitives like semaphores, locks, or condition variables
Skip it when
- You are communicating across different isolates rather than within a single isolate
- High-level abstractions or reactive streams can handle your concurrency needs
Strengths
- Lightweight and straightforward API
- Includes helpful examples for complex patterns like producer-consumer
Weaknesses
- Marked as unsupported in an earlier changelog entry (version 0.2.1), though later updated for Dart 3
- Limited to synchronization within a single isolate
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
not documented
import 'dart:async';
import 'package:semaphore/semaphore.dart';
Future<void> main() async {
const maxCount = 3;
final sm = LocalSemaphore(maxCount);
await sm.acquire();
try {
// Do work
} finally {
sm.release();
}
}Alternatives
Packages that do the same job and could replace semaphore.
- isolate_channel
Communication channels for isolates based on Flutter's platform channels.
82Compare - jinja
Jinja2 template engine port for Dart supporting variables, control structures, and template inheritance.
84Compare - system_resources_2
Access CPU and memory usage, container-aware, pure Dart on Linux, FFI on macOS
59Compare