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

30 views
Skip to first unread message

Morlay Null

unread,
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. https://go.dev/blog/context

Here is an implament https://pub.dev/packages/contextdart

I use it to implement:

* cancelable http client https://pub.dev/packages/roundtripper
* logr https://pub.dev/packages/logr, which get Logger instance from context to avoid passing the Logger instance in each class structure.

William Hesse

unread,
Jan 27, 2022, 6:29:46 AMJan 27
to mi...@dartlang.org
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 https://dart.dev/articles/archive/zones

--
For more ways to connect visit https://dart.dev/community
---
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 misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/fc8bbf2f-22cc-417e-b756-e9850f46bf93n%40dartlang.org.


--

       - William Hesse
Reply all
Reply to author
Forward
0 new messages