File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
gcopypaste/app/core/utils Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -13,18 +13,18 @@ import {
13
13
TypeaheadOutput ,
14
14
withTheme2 ,
15
15
} from '@grafana/ui' ;
16
- import { LocalStorageValueProvider } from 'app/core/components/LocalStorageValueProvider' ;
17
- import {
18
- CancelablePromise ,
19
- isCancelablePromiseRejection ,
20
- makePromiseCancelable ,
21
- } from 'app/core/utils/CancelablePromise' ;
22
16
import { LanguageMap , languages as prismLanguages } from 'prismjs' ;
23
17
import React , { ReactNode } from 'react' ;
24
18
import { Plugin } from 'slate' ;
25
19
import { Editor } from 'slate-react' ;
26
20
27
21
import { PrometheusDatasource } from '../datasource' ;
22
+ import { LocalStorageValueProvider } from '../gcopypaste/app/core/components/LocalStorageValueProvider' ;
23
+ import {
24
+ CancelablePromise ,
25
+ isCancelablePromiseRejection ,
26
+ makePromiseCancelable ,
27
+ } from '../gcopypaste/app/core/utils/CancelablePromise' ;
28
28
import { roundMsToMin } from '../language_utils' ;
29
29
import { PromOptions , PromQuery } from '../types' ;
30
30
Original file line number Diff line number Diff line change
1
+ // https://github.com/facebook/react/issues/5465
2
+
3
+ export interface CancelablePromise < T > {
4
+ promise : Promise < T > ;
5
+ cancel : ( ) => void ;
6
+ }
7
+
8
+ export interface CancelablePromiseRejection {
9
+ isCanceled : boolean ;
10
+ }
11
+
12
+ export function isCancelablePromiseRejection ( promise : unknown ) : promise is CancelablePromiseRejection {
13
+ return typeof promise === 'object' && promise !== null && 'isCanceled' in promise ;
14
+ }
15
+
16
+ export const makePromiseCancelable = < T > ( promise : Promise < T > ) : CancelablePromise < T > => {
17
+ let hasCanceled_ = false ;
18
+
19
+ const wrappedPromise = new Promise < T > ( ( resolve , reject ) => {
20
+ const canceledPromiseRejection : CancelablePromiseRejection = { isCanceled : true } ;
21
+ promise . then ( ( val ) => ( hasCanceled_ ? reject ( canceledPromiseRejection ) : resolve ( val ) ) ) ;
22
+ promise . catch ( ( error ) => ( hasCanceled_ ? reject ( canceledPromiseRejection ) : reject ( error ) ) ) ;
23
+ } ) ;
24
+
25
+ return {
26
+ promise : wrappedPromise ,
27
+ cancel ( ) {
28
+ hasCanceled_ = true ;
29
+ } ,
30
+ } ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments