synchronized_call 1.0.0 copy "synchronized_call: ^1.0.0" to clipboard
synchronized_call: ^1.0.0 copied to clipboard

outdated

Lock mechanism to prevent concurrent access to asynchronous code.

synchronized_call #

Synchronized mechanism for async function calls, to prevent concurrent access to the asynchronous code.

Feature #

  • Pure Dart language. No dependencies

Inspired by synchronized package, but it erase weakness that with so many Completer create at one time, and support to observer all the bloc is finished.

Example #

Consider the following dummy code

  Future write(int index) async {
    await Future.delayed(Duration(microseconds: 1));
    print('$index');
  }

  Future writeBatch(List<int> indexes) async {
    for (var i in indexes) {
      await write(i);
    }
  }

  void doWrite() async {
    await writeBatch([1, 2, 3, 4, 5]);
    print(' ');
  }

Doing

doWrite();
doWrite();
doWrite();

/// will print: '111222333444555'
/// but we expect: '123451234512345'

So using the Lock in synchronized_call package:

Lock lock = Lock();

lock.call(doWrite);
lock.call(doWrite);
lock.call(doWrite);

/// now the output will be: '123451234512345'

Features and bugs #

Please feel free to: request new features and bugs at the issue tracker

9
likes
0
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

Lock mechanism to prevent concurrent access to asynchronous code.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on synchronized_call