weblocks 0.0.0-wip copy "weblocks: ^0.0.0-wip" to clipboard
weblocks: ^0.0.0-wip copied to clipboard

A native, asynchronous, read-write lock that works across isolates and tabs.

Locks #

package:async_lock is a mutex implementation that:

  • works across isolates on native platforms, and across tabs and workers on the web.
  • is asynchronous.
  • supports shared and exclusive access to locks.
  • identifies mutexes by name, and doesn't require prior communication.
  • can query the state of mutexes.

On the web, package:async_lock is implemented with of the Web Locks API. On native platforms, dart:ffi is used with a native lock implementation written in Rust. Of course, both platforms use an identical API, and behave similarly.

Getting started #

Note that this package requires the native-assets experiment, meaning that it is currently only available on dev builds of the Dart SDK.

Apart from that, dart pub add async_lock is the only step to install this package. Build hooks will automatically download native sources where required.

Usage #

The LockManager interface is the main entrypoint to request locks, available through the lockManager getter:

import 'package:async_lock/async_lock.dart';

void main() async {
  final lockName = 'my-lock';

  final held = await lockManager.request(lockName).completion;
  print('Holds lock: ${held != null}'); // true

  held!.release();
}

For more details, see the documentation or the full example.

0
likes
0
points
19
downloads

Publisher

verified publishersimonbinder.eu

Weekly Downloads

A native, asynchronous, read-write lock that works across isolates and tabs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

code_assets, ffi, hooks, path, web

More

Packages that depend on weblocks