ctx 0.0.3 copy "ctx: ^0.0.3" to clipboard
ctx: ^0.0.3 copied to clipboard

Immutable context for carrying data through an application.

ctx #

An immutable context for carrying data, deadlines, and cancellation signals through your application.

Usage #

Carrying Values #

import 'package:ctx/ctx.dart';

void main() {
  final ctx = Context.empty()
      .withValue('user', 'alice')
      .withValue('role', 'admin');

  print(ctx['user']); // alice

  // Derive a new context without mutating the original:
  final scoped = ctx.withValue('role', 'editor');
  print(ctx['role']);    // admin
  print(scoped['role']); // editor
}

Cancellation & Timeouts #

// Explicit cancellation
final (ctx, cancel) = Context.empty().withCancel();
cancel();

// Automatic timeout
final (ctxTimeout, cancelTimeout) = Context.empty().withTimeout(Duration(seconds: 5));

// Non-cancelable branch
final detached = ctx.withoutCancel();
0
likes
160
points
370
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Immutable context for carrying data through an application.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on ctx