Urgent.News

What's breaking now, across thousands of outlets.

Tech

Share State Across Dart Isolates Without Losing Your Mind: Enter shared_map

This is Part 3 of the Dart and Flutter series—practical guides, architectural deep dives, and hard-earned engineering lessons from the field. Each article is completely standalone. Dart’s concurrency model is built on Isolates . Unlike threads in Java, C++, or Go, Dart isolates share no memory. Each isolate has its own private heap and its own single-threaded event loop. This "share-nothing"…

Dart’s concurrent programming model relies on Isolates, which do not share memory. Each isolate maintains its own private heap and single-threaded event loop. While this design prevents data races, deadlocks, and threading issues, it also prevents isolates from sharing data. When you need to share data, you typically face two suboptimal solutions: serializing and copying data structures or building a custom message-passing server using ReceivePort and SendPort.

Shared_map offers a superior alternative. Developed by experienced Dart engineer Graciliano M. Passos, shared_map provides a synchronized Map data structure that can be shared across Dart isolates. Key benefits of shared_map include zero dependencies, flawless quality, universal platform support, and familiar async Map methods for easy integration.

The library employs the reference pattern, where a lightweight, serializable token is generated and transferred between isolates. This token allows the worker isolate to reconstruct a proxy instance of the shared Map, enabling seamless reads, writes, and mutations while ensuring synchronization across all isolates. In a practical example, two background isolates read and write to a shared cache, demonstrating how shared_map simplifies cross-isolate communication compared to traditional messaging approaches.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Finally Teaching Python to Think 🐍

When I started learning Python, I was mostly telling it what to print. Then I discovered if statements and loops. And suddenly, Python could make decisions, repeat tasks, and even help me analyse…

More from Sunday 20 September →