Skip to content

Synchronization primitives for asynchronous Dart code: Event, Lock and Semaphore

License

Notifications You must be signed in to change notification settings

Serious-senpai/async-locks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-locks

Package Test Documentation Build

Effortlessly synchronize asynchronous operations in your Dart applications

This package provides a set of intuitive primitives inspired by Python's established concurrency features, making it easy to manage shared resources and prevent race conditions in asynchronous code.

Key features:

  • Familiar concepts: Lock, Event, and Semaphore for a smooth transition from Python's concurrency model.
  • Optimized for Dart: Efficient implementation tailored for Dart's asynchronous programming capabilities.
  • Clear and concise documentation: Quickly understand how to use each primitive effectively.

Installation:

Add async_locks as a dependency in your pubspec.yaml file:

dependencies:
  async_locks: ^latest_version

Sample usage:

import "dart:io";
import "package:async_locks/async_locks.dart";

final lock = Lock();

Future<void> randomAsyncFunction() async {
  final result = await lock.run(() async => await accessSharedState());
}

Synchronization primitives:

  • Lock: A mutex lock that guarantees exclusive access to a shared state, preventing race conditions.
  • Event: An object used to notify multiple futures that a specific event has occurred.
  • Semaphore: A synchronization primitive that allows a limited number of futures to acquire it concurrently.

Inspired by Python's asyncio:

While the implementation details differ, async_locks offers a familiar approach for developers coming from a Python background. See the Python documentation for reference: https://docs.python.org/3/library/asyncio-sync.html

About

Synchronization primitives for asynchronous Dart code: Event, Lock and Semaphore

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages