Consider official `dart:context` implements golang's context.Context pattern

Skip to first unread message

Morlay Null

Jan 27, 2022, 5:21:28 AMJan 27
to Dart Misc
Golang's `context.Context` is a sucessful pattern for flow controling and context carrier.

When we use `dart` to make http servers, 
this pattern will be very useful.

Here is an implament

I use it to implement:

* cancelable http client
* logr, which get Logger instance from context to avoid passing the Logger instance in each class structure.

William Hesse

Jan 27, 2022, 6:29:46 AMJan 27
Dart has zones, which accomplish many of the same objectives.
A new Zone can be created for an Http request, and it will be inherited by all synchronous and asynchronous code started by that request.
Data and handlers can be associated with that zone.
So perhaps Context can be implemented with zones, or zones can be used directly where this Context would be used.

See the description of zones at

For more ways to connect visit
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit


       - William Hesse
Reply all
Reply to author
0 new messages