reader_writer_lock 0.2.1

Dart native js
Flutter Android iOS web

Simple reader-writer-lock implementation upon mutex package

reader_writer_lock #

Simple reader-writer-lock implementation upon mutex package.

Usage #

The package realizes synchronized like syntax to reduce use of try-finally for releasing locks.

import 'package:reader_writer_lock/reader_writer_lock.dart';

final rwlock = ReaderWriterLock();

// reader-lock
await rwlock.readerLock(() async {
    // Do reader task here
});

// writer-lock
await rwlock.writerLock(() async {
    // Do writer task here
});

If you want to do some Test-and-Set operation, you can use readerLockUpgradable method to do so. It has a parameter, named upgrade and you can call the function to upgrader reader-lock to writer-lock.

import 'package:reader_writer_lock/reader_writer_lock.dart';

final rwlock = ReaderWriterLock();

// reader-lock
await rwlock.readerLockUpgradable((upgrade) async {
    // Do reader task here

    // Upgrade reader-lock to writer-lock
    await upgrade();

    // Do writer task here
});
0
likes
80
pub points
55%
popularity

Simple reader-writer-lock implementation upon mutex package

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

espresso3389@gmail.com

License

MIT (LICENSE)

More

Packages that depend on reader_writer_lock