File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
src/plugins/reverseGeocoder/utils Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -32,13 +32,21 @@ const parser = new Parser({
3232 tagNameProcessors : [ processors . stripPrefix ] ,
3333} )
3434
35+ let abortController : AbortController | null = null
36+
3537export async function reverseGeocode (
3638 url : string ,
3739 coordinate : [ number , number ]
3840) : Promise < ReverseGeocoderFeature > {
41+ if ( abortController ) {
42+ abortController . abort ( )
43+ abortController = null
44+ }
45+ abortController = new AbortController ( )
3946 const response = await fetch ( url , {
4047 method : 'POST' ,
4148 body : buildPostBody ( coordinate ) ,
49+ signal : abortController . signal ,
4250 } )
4351
4452 const parsedBody = await parser . parseStringPromise ( await response . text ( ) )
@@ -142,6 +150,7 @@ if (import.meta.vitest) {
142150 expect ( fetchMock ) . toHaveBeenCalledWith ( testUrl , {
143151 method : 'POST' ,
144152 body : buildPostBody ( testCoordinates ) ,
153+ signal : abortController ?. signal ,
145154 } )
146155
147156 expect ( feature ) . toEqual < ReverseGeocoderFeature > ( {
You can’t perform that action at this time.
0 commit comments