github.com/grafana/pyroscope@v1.18.0/public/app/redux/reducers/continuous/singleView.thunks.ts (about) 1 import { renderSingle, RenderOutput } from '@pyroscope/services/render'; 2 import { RequestAbortedError } from '@pyroscope/services/base'; 3 import { addNotification } from '../notifications'; 4 import { createAsyncThunk } from '../../async-thunk'; 5 import { ContinuousState } from './state'; 6 7 let singleViewAbortController: AbortController | undefined; 8 9 export const fetchSingleView = createAsyncThunk< 10 RenderOutput, 11 null, 12 { state: { continuous: ContinuousState } } 13 >('continuous/singleView', async (_, thunkAPI) => { 14 if (singleViewAbortController) { 15 singleViewAbortController.abort(); 16 } 17 18 singleViewAbortController = new AbortController(); 19 thunkAPI.signal = singleViewAbortController.signal; 20 21 const state = thunkAPI.getState(); 22 const res = await renderSingle(state.continuous, singleViewAbortController); 23 24 if (res.isOk) { 25 return Promise.resolve(res.value); 26 } 27 28 if (res.isErr && res.error instanceof RequestAbortedError) { 29 return Promise.reject(res.error); 30 } 31 32 thunkAPI.dispatch( 33 addNotification({ 34 type: 'danger', 35 title: 'Failed to load single view data', 36 message: res.error.message, 37 }) 38 ); 39 40 return Promise.reject(res.error); 41 });