22// SPDX-License-Identifier: Apache-2.0
33import { ProgressLocation , l10n , window } from "vscode" ;
44
5- import { OnLogFn , RunResult } from "." ;
5+ import type { OnLogFn , RunResult } from "." ;
66
77export abstract class Session {
8+ protected _rejectRun : ( reason ?: unknown ) => void | undefined ;
9+
810 protected _onSessionLogFn : OnLogFn | undefined ;
911 public set onSessionLogFn ( value : OnLogFn ) {
1012 this . _onSessionLogFn = value ;
@@ -30,8 +32,27 @@ export abstract class Session {
3032 }
3133
3234 protected abstract establishConnection ( ) : Promise < void > ;
33- abstract run ( code : string ) : Promise < RunResult > ;
35+
36+ run ( code : string , ...args ) : Promise < RunResult > {
37+ return new Promise ( ( resolve , reject ) => {
38+ this . _rejectRun = reject ;
39+ this . _run ( code , ...args )
40+ . then ( resolve , reject )
41+ . finally ( ( ) => ( this . _rejectRun = undefined ) ) ;
42+ } ) ;
43+ }
44+ protected abstract _run ( code : string , ...args ) : Promise < RunResult > ;
45+
3446 cancel ?( ) : Promise < void > ;
35- abstract close ( ) : Promise < void > | void ;
47+
48+ close ( ) : Promise < void > | void {
49+ if ( this . _rejectRun ) {
50+ this . _rejectRun ( { message : l10n . t ( "The SAS session has closed." ) } ) ;
51+ this . _rejectRun = undefined ;
52+ }
53+ return this . _close ( ) ;
54+ }
55+ protected abstract _close ( ) : Promise < void > | void ;
56+
3657 abstract sessionId ?( ) : string | undefined ;
3758}
0 commit comments