D
BLoC PatternHard50 XP4 min read

What are event transformers in Bloc?

TL;DR: Event transformers control how a Bloc processes multiple events of the same type. The default is sequential (one at a time). Use concurrent() for parallel processing, droppable() to ignore events while one is in flight, or restartable() for search.

Full Answer

The bloc_concurrency package provides production-ready transformers for common patterns.

  • sequential() (default): Queue events, process one at a time
  • concurrent(): Process all events in parallel
  • droppable(): Ignore new events while one is processing (good for form submissions)
  • restartable(): Cancel in-flight handler, start fresh (good for search)
🎯

Use restartable() for search-as-you-type — it cancels the previous HTTP request when a new character is typed, so only the latest query completes.

Code Examples

dartEvent transformers for search and submit
Output
// restartable: typing quickly cancels previous in-flight requests
// droppable: double-tap on submit does nothing

Common Mistakes

  • Using default sequential() for search — queues up all keystrokes, floods the API
  • Not using droppable() for payment/auth submission buttons — risk of double-posting

Interview Tip

💡

restartable() for search and droppable() for submit are the two most important transformers in production apps. Show you've considered race conditions.

#event-transformer#debounce#throttle#concurrent#sequential