6
6
#![ deny( clippy:: all) ]
7
7
8
8
use aws_config:: Region ;
9
+ use std:: sync:: LazyLock ;
10
+
11
+ static DAFNY_TOKIO_RUNTIME : LazyLock < tokio:: runtime:: Runtime > = LazyLock :: new ( || {
12
+ tokio:: runtime:: Builder :: new_multi_thread ( )
13
+ . enable_all ( )
14
+ . build ( )
15
+ . unwrap ( )
16
+ } ) ;
9
17
10
18
impl crate :: r#software:: amazon:: cryptography:: services:: kms:: internaldafny:: _default {
11
19
#[ allow( non_snake_case) ]
@@ -14,11 +22,17 @@ impl crate::r#software::amazon::cryptography::services::kms::internaldafny::_def
14
22
dafny_runtime:: dafny_runtime_conversions:: unicode_chars_false:: dafny_string_to_string (
15
23
region,
16
24
) ;
17
- let shared_config = tokio:: task:: block_in_place ( || {
18
- tokio:: runtime:: Handle :: current ( ) . block_on ( async {
19
- aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
20
- } )
21
- } ) ;
25
+
26
+ let shared_config = match tokio:: runtime:: Handle :: try_current ( ) {
27
+ Ok ( curr) => tokio:: task:: block_in_place ( || {
28
+ curr. block_on ( async {
29
+ aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
30
+ } )
31
+ } ) ,
32
+ Err ( _) => DAFNY_TOKIO_RUNTIME . block_on ( aws_config:: load_defaults (
33
+ aws_config:: BehaviorVersion :: v2024_03_28 ( ) ,
34
+ ) ) ,
35
+ } ;
22
36
23
37
let shared_config = shared_config
24
38
. to_builder ( )
@@ -34,11 +48,17 @@ impl crate::r#software::amazon::cryptography::services::kms::internaldafny::_def
34
48
35
49
#[ allow( non_snake_case) ]
36
50
pub fn KMSClient ( ) -> :: std:: rc:: Rc < crate :: r#_Wrappers_Compile:: Result < :: dafny_runtime:: Object < dyn crate :: software:: amazon:: cryptography:: services:: kms:: internaldafny:: types:: IKMSClient > , :: std:: rc:: Rc < crate :: software:: amazon:: cryptography:: services:: kms:: internaldafny:: types:: Error > > > {
37
- let shared_config = tokio:: task:: block_in_place ( || {
38
- tokio:: runtime:: Handle :: current ( ) . block_on ( async {
39
- aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
40
- } )
41
- } ) ;
51
+ let shared_config = match tokio:: runtime:: Handle :: try_current ( ) {
52
+ Ok ( curr) => tokio:: task:: block_in_place ( || {
53
+ curr. block_on ( async {
54
+ aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
55
+ } )
56
+ } ) ,
57
+ Err ( _) => DAFNY_TOKIO_RUNTIME . block_on ( aws_config:: load_defaults (
58
+ aws_config:: BehaviorVersion :: v2024_03_28 ( ) ,
59
+ ) ) ,
60
+ } ;
61
+
42
62
let inner = aws_sdk_kms:: Client :: new ( & shared_config) ;
43
63
let client = crate :: deps:: com_amazonaws_kms:: client:: Client { inner } ;
44
64
let dafny_client = :: dafny_runtime:: upcast_object ( ) ( :: dafny_runtime:: object:: new ( client) ) ;
0 commit comments