| 1004 | * @returns {T} |
| 1005 | */ |
| 1006 | export function flushSync(fn) { |
| 1007 | var was_flushing_sync = is_flushing_sync; |
| 1008 | is_flushing_sync = true; |
| 1009 | |
| 1010 | try { |
| 1011 | var result; |
| 1012 | |
| 1013 | if (fn) { |
| 1014 | if (current_batch !== null && !current_batch.is_fork) { |
| 1015 | current_batch.flush(); |
| 1016 | } |
| 1017 | |
| 1018 | result = fn(); |
| 1019 | } |
| 1020 | |
| 1021 | while (true) { |
| 1022 | flush_tasks(); |
| 1023 | |
| 1024 | if (current_batch === null) { |
| 1025 | return /** @type {T} */ (result); |
| 1026 | } |
| 1027 | |
| 1028 | current_batch.flush(); |
| 1029 | } |
| 1030 | } finally { |
| 1031 | is_flushing_sync = was_flushing_sync; |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | function infinite_loop_guard() { |
| 1036 | if (DEV) { |