@@ -3,56 +3,56 @@ import { config } from './common';
33import { Producer } from '../src' ;
44
55if ( typeof ( Promise as any ) . withResolvers === 'undefined' ) {
6- ( Promise as any ) . withResolvers = function ( ) {
7- let resolve : ( ( value ?: any ) => void ) | null = null ;
8- let reject : ( ( reason ?: any ) => void ) | null = null ;
9- const promise = new Promise ( ( res , rej ) => {
10- resolve = res ;
11- reject = rej ;
12- } ) ;
13- return { promise, resolve, reject } ;
14- } ;
6+ ( Promise as any ) . withResolvers = function ( ) {
7+ let resolve : ( ( value ?: any ) => void ) | null = null ;
8+ let reject : ( ( reason ?: any ) => void ) | null = null ;
9+ const promise = new Promise ( ( res , rej ) => {
10+ resolve = res ;
11+ reject = rej ;
12+ } ) ;
13+ return { promise, resolve, reject } ;
14+ } ;
1515}
1616
1717const rl = readline . createInterface ( {
18- input : process . stdin ,
19- output : process . stdout
18+ input : process . stdin ,
19+ output : process . stdout
2020} ) ;
2121
2222void async function ( ) {
23- const producer = new Producer ( 'GID_GROUP' , {
24- nameServer : config . nameServer ,
25- } ) ;
23+ const producer = new Producer ( 'GID_GROUP' , {
24+ nameServer : config . nameServer
25+ } ) ;
26+
27+ // producer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN')
2628
27- // producer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN')
28-
29- await producer . start ( ) ;
30-
31- while ( 1 ) {
32- const { promise, resolve, reject } = ( Promise as any ) . withResolvers ( ) ;
33- rl . question ( 'Enter input: ' , async ( input : string ) => {
34- await producer . send ( 'TP_TOPIC' , input ) . catch ( reject ) ;
35- resolve ( ) ;
36- } ) ;
37- await promise ;
38- }
39-
40- // producer.start(async function() {
41- // console.log('producer started');
42- // while(1) {
43- // const { promise, resolve, reject } = Promise.withResolvers()
44- // rl.question('Enter input: ', input => {
45- // producer.send('TP_TOPIC', input, function(err, ret) {
46- // if (err) {
47- // console.error(err);
48- // reject(err)
49- // }
50- // console.log(ret);
51- // resolve(ret)
52- // });
53- // });
54- // await promise.catch(console.error);
55- // }
56- // });
29+ await producer . start ( ) ;
30+
31+ while ( 1 ) {
32+ const { promise, resolve, reject } = ( Promise as any ) . withResolvers ( ) ;
33+ rl . question ( 'Enter input: ' , async ( input : string ) => {
34+ await producer . send ( 'TP_TOPIC' , input ) . catch ( reject ) ;
35+ resolve ( ) ;
36+ } ) ;
37+ await promise ;
38+ }
39+
40+ // producer.start(async function() {
41+ // console.log('producer started');
42+ // while(1) {
43+ // const { promise, resolve, reject } = Promise.withResolvers()
44+ // rl.question('Enter input: ', input => {
45+ // producer.send('TP_TOPIC', input, function(err, ret) {
46+ // if (err) {
47+ // console.error(err);
48+ // reject(err)
49+ // }
50+ // console.log(ret);
51+ // resolve(ret)
52+ // });
53+ // });
54+ // await promise.catch(console.error);
55+ // }
56+ // });
5757
5858} ( ) ;
0 commit comments