system library

Provides fundamental system types for resource management, threading, and common exceptions.

This library contains core system abstractions inspired by the .NET System namespace, including disposal patterns, cancellation tokens, and base exception types.

Resource Management

Dispose of resources properly:

class MyResource implements Disposable {
  @override
  void dispose() {
    // Clean up resources
  }
}

// Synchronous disposal
using((resource) {
  // Use resource
}, MyResource());

// Asynchronous disposal
await using((resource) async {
  // Use resource
}, MyAsyncResource());

Cancellation Support

Cancel long-running operations:

final cts = CancellationTokenSource();

// Cancel after timeout
cts.cancelAfter(Duration(seconds: 30));

// Perform cancellable work
await doWorkAsync(cts.token);

// Cancel manually
cts.cancel();

Exception Types

Standard exception types for common error conditions:

throw ArgumentNullException('paramName');
throw ObjectDisposedException('MyClass');
throw OperationCancelledException();

Classes

CallbackNode
All of the state associated a registered callback, in a node that's part of a linked list of registered callbacks.
CancellationCallbackInfo
CancellationToken
Propagates notification that operations should be canceled.
CancellationTokenRegistration
CancellationTokenSource
Signals to a CancellationToken that it should be canceled.
IAsyncDisposable
Provides a mechanism for releasing unmanaged resources asynchronously.
IDisposable
Provides a mechanism for releasing unmanaged resources.
LinkedNCancellationTokenSource
Registrations
Set of all the registrations in the token source.

Mixins

EnumFlags

Extensions

EnumFlagsExtension on int

Functions

equals(String value1, String value2, {bool ignoreCase = true}) bool
isNullOrEmpty(String? value) bool
isNullOrWhitespace(String? value) bool

Typedefs

AsyncDisposable = IAsyncDisposable
Alias for IAsyncDisposable for backwards compatibility.
CallbackRegistration = void Function(Object? state)
CancellationCallback = void Function(Object? state)
Disposable = IDisposable
Alias for IDisposable for backwards compatibility.
Task = Future<void>
TimerCallback = void Function(Object? state)

Exceptions / Errors

ArgumentException
The exception that is thrown when one of the arguments provided to a method is not valid.
ArgumentNullException
An exception that is thrown when a method is invoked and at least one of the passed arguments is null but should never be null.
ObjectDisposedException
/// The exception that is thrown when accessing an object that was disposed.
OperationCanceledException
The exception that is thrown in a thread upon cancellation of an operation that the thread was executing.
SystemException
This class is provided as a means to differentiate between system exceptions and application exceptions.