contextdart

Creator: coderz1093

Last updated:

0 purchases

contextdart Image
contextdart Images

Languages

Categories

Add to Cart

Description:

contextdart

pure golang context.Context implements in dart #


Totally inspected by context.Context from golang, and dart style fit.
Usage #
inject value or singleton in context
import 'package:contextdart/contextdart.dart';

class Logger {
info(String msg) {

}
}

void main() async {
var ctx = Context.withValue(Logger());

ctx.run(() {
var log = Context.value<Logger>();

log?.info("log");
});
}
copied to clipboard
Cancelable context. #
import 'package:contextdart/contextdart.dart';

class Logger {
info(String msg);
}

void main() async {
var cctx = Context.withCancel();

cctx.run(() {
doAction();
doDBAction();

// cancel
cctx.cancel();
});
}

doAction() async {
return await Future.any([
// if canceled, should ignore real action
Context.done?.fisrt,
Future(() => "do action"),
].whereType<Future>());
}

doDBAction() async {
Context.done?.listen(() {
// do some think like db rollback.
});
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.