An implementation of disposable for Dart.

Build Status

Introduction


Software should be like Kleenex, strong and disposable!

  • Gotta have Dart: http://dartlang.org

This library originated as a mechinism for cleaning up resources when you're done with them.

Features

  • IDisposable - interface
  • IAsyncDisposable - interface

  • Disposable - class

  • AsyncDisposable - class

  • CompositeDisposable - class

  • using - global function

  • usingAsync - global function

40+ unit tests provide more detailed examples of usage!

Getting Started

1\. Add the following to your project's pubspec.yaml and run pub install.

dependencies:
  disposable: any

2\. Add the correct import for your project.

import 'package:disposable/disposable.dart';

3\. Start using.

Naive/pointless example:

var recPort = new ReceivePort();
// Use the default constructor of both Disposable and AsyncDisposable
// to do the closing, nulling and other cleanup needed
var disposable = new Disposable(() => recPort.close());
... do stuff with recPort
disposable.dispose();

Better example:

var recPort = new ReceivePort();
using(new Disposable(() => recPort.close()), (disposable) {
	... do stuff with recPort
});

And if you have something that actually implements IDisposable:

using(new MyThing(), (myThing) {
	... do stuff with myThing
});

Finally, if you have something that executes async using a Future:

example from in-progress library Jester @ Git

usingAsync(new SafeReceivePort(), (SafeReceivePort safePort) {
  SendPort sendPort = safePort.toSendPort();
  sendPort.send('stuff');
  return safePort.messages.first; // Return any future here
})
.then((dynamic message) {
  ... message should be 'stuff'
  ... SafeReceivePort will be cleaned up for you, no need to remember to close
});

Goals

  • Provide a mechanism to help manage cleanup in applications.
  • Originated as a way to help ensure closure of isolate ReceivePorts
  • Provide using semantics to auto dispose elements through scope

Version

0.1.2 ish

Tech

  • Dart - Dartlang.org: get the JS out!
  • Disposable - An implementation of disposable for Dart.

Installation

License

https://github.com/Vizidrix/disposable/blob/master/LICENSE


Edited

  • 26-April-2013 initial release
  • 28-April-2013 bumped to 0.1.0
  • 05-May-2013 updated packages and minor doc update
  • 06-July-2013 fixed some async disposable tests

Credits

Libraries

disposable