disposable 0.0.2
disposable: ^0.0.2 copied to clipboard
An implementation of disposable for Dart.
An implementation of disposable for Dart.
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
- Disposable - class
- CompositeDisposable - class
- using - global function
- usingAsync - global function
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();
var disposable = new Disposable(() => recPort.close());
... do stuff with recPort
disposable.close();
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.0.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
Credits #
- Vizidrix https://github.com/organizations/Vizidrix
- Perry Birch https://github.com/PerryBirch
