using 1.0.2 copy "using: ^1.0.2" to clipboard
using: ^1.0.2 copied to clipboard

This package provides a `Releasable` mixin to upgrade any class with automatic cleanup and finalization features, similar to C#'s `IDisposable` and Java's `AutoCloseable`. Extension methods enhance th [...]

example/using_example.dart

import 'dart:convert';

import 'package:using/using.dart';

import 'impl/some_crypto_algorithm.dart';
import 'impl/utils.dart';

void main() {
  // enable tracking
  ReleasableTracker.enable();

  final hash = SomeCryptoAlgorithm().use((crypto) {
    Print.blue('hashing...');
    crypto
      ..update(utf8.encode('password'))
      ..update(utf8.encode('salt'))
      ..update(utf8.encode('secret message'));
    return crypto.digest();
  });
  Print.green('hash = ${dumpBytes(hash)}');

  Print.std('');

  // report
  Print.std('Tracked count = ${ReleasableTracker.releasables.length}');
}
0
likes
0
pub points
47%
popularity

Publisher

unverified uploader

This package provides a `Releasable` mixin to upgrade any class with automatic cleanup and finalization features, similar to C#'s `IDisposable` and Java's `AutoCloseable`. Extension methods enhance the development experience with constructs close to `using` in C# and `try-with-resource` in Java.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on using