Bloc: How can I cancel event in bloc?

Created on 1 Jun 2020  路  2Comments  路  Source: felangel/bloc

I have two events, execution of PrepareEpubBook event lasts 10-15 sec. During this execution, I call from UI CancelBookPreparing event, but this event executes only after PrepareEpubBook event finishes.

if (event is CancelBookPreparing) { _cancelToken.cancel(); yield BookOpeningCancel(); } else if (event is PrepareEpubBook) { ... await _downloadBook(event.bookData.downloadURL, bookPath); ...
How can I cancel execution of PrepareEpubBook event and make CancelBookPreparing event? Or How can I run CancelBookPreparing event during PrepareEpubBook event?

question

Most helpful comment

Hi @RomanSoviak 馃憢

You could override transformEvents and use switchMap instead of the default asyncExpand. This will drop the previous event when a new event is entering bloc.

All 2 comments

Hi @RomanSoviak 馃憢

You could override transformEvents and use switchMap instead of the default asyncExpand. This will drop the previous event when a new event is entering bloc.

@RollyPeres thanks!

Was this page helpful?
0 / 5 - 0 ratings