@@ -78,20 +78,20 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
7878 throw new Error ( 'At least one protocol must be specified' )
7979 }
8080
81- options ?. log . trace ( 'select: write ["%s", "%s"]' , PROTOCOL_ID , protocol )
81+ options ?. log ? .trace ( 'select: write ["%s", "%s"]' , PROTOCOL_ID , protocol )
8282 const p1 = uint8ArrayFromString ( `${ PROTOCOL_ID } \n` )
8383 const p2 = uint8ArrayFromString ( `${ protocol } \n` )
8484 await multistream . writeAll ( lp , [ p1 , p2 ] , options )
8585
86- options ?. log . trace ( 'select: reading multistream-select header' )
86+ options ?. log ? .trace ( 'select: reading multistream-select header' )
8787 let response = await multistream . readString ( lp , options )
88- options ?. log . trace ( 'select: read "%s"' , response )
88+ options ?. log ? .trace ( 'select: read "%s"' , response )
8989
9090 // Read the protocol response if we got the protocolId in return
9191 if ( response === PROTOCOL_ID ) {
92- options ?. log . trace ( 'select: reading protocol response' )
92+ options ?. log ? .trace ( 'select: reading protocol response' )
9393 response = await multistream . readString ( lp , options )
94- options ?. log . trace ( 'select: read "%s"' , response )
94+ options ?. log ? .trace ( 'select: read "%s"' , response )
9595 }
9696
9797 // We're done
@@ -101,11 +101,11 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
101101
102102 // We haven't gotten a valid ack, try the other protocols
103103 for ( const protocol of protocols ) {
104- options ?. log . trace ( 'select: write "%s"' , protocol )
104+ options ?. log ? .trace ( 'select: write "%s"' , protocol )
105105 await multistream . write ( lp , uint8ArrayFromString ( `${ protocol } \n` ) , options )
106- options ?. log . trace ( 'select: reading protocol response' )
106+ options ?. log ? .trace ( 'select: reading protocol response' )
107107 const response = await multistream . readString ( lp , options )
108- options ?. log . trace ( 'select: read "%s" for "%s"' , response , protocol )
108+ options ?. log ? .trace ( 'select: read "%s" for "%s"' , response , protocol )
109109
110110 if ( response === protocol ) {
111111 return { stream : lp . unwrap ( ) , protocol }
@@ -163,7 +163,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
163163 if ( ! sentProtocol ) {
164164 sendingProtocol = true
165165
166- options ?. log . trace ( 'optimistic: write ["%s", "%s", data(%d)] in sink' , PROTOCOL_ID , protocol , buf . byteLength )
166+ options ?. log ? .trace ( 'optimistic: write ["%s", "%s", data(%d)] in sink' , PROTOCOL_ID , protocol , buf . byteLength )
167167
168168 const protocolString = `${ protocol } \n`
169169
@@ -176,7 +176,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
176176 buf
177177 ) . subarray ( )
178178
179- options ?. log . trace ( 'optimistic: wrote ["%s", "%s", data(%d)] in sink' , PROTOCOL_ID , protocol , buf . byteLength )
179+ options ?. log ? .trace ( 'optimistic: wrote ["%s", "%s", data(%d)] in sink' , PROTOCOL_ID , protocol , buf . byteLength )
180180
181181 sentProtocol = true
182182 sendingProtocol = false
@@ -198,7 +198,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
198198
199199 async function negotiate ( ) : Promise < void > {
200200 if ( negotiating ) {
201- options ?. log . trace ( 'optimistic: already negotiating %s stream' , protocol )
201+ options ?. log ? .trace ( 'optimistic: already negotiating %s stream' , protocol )
202202 await doneNegotiating . promise
203203 return
204204 }
@@ -208,13 +208,13 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
208208 try {
209209 // we haven't sent the protocol yet, send it now
210210 if ( ! sentProtocol ) {
211- options ?. log . trace ( 'optimistic: doing send protocol for %s stream' , protocol )
211+ options ?. log ? .trace ( 'optimistic: doing send protocol for %s stream' , protocol )
212212 await doSendProtocol ( )
213213 }
214214
215215 // if we haven't read the protocol response yet, do it now
216216 if ( ! readProtocol ) {
217- options ?. log . trace ( 'optimistic: doing read protocol for %s stream' , protocol )
217+ options ?. log ? .trace ( 'optimistic: doing read protocol for %s stream' , protocol )
218218 await doReadProtocol ( )
219219 }
220220 } finally {
@@ -233,12 +233,12 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
233233 sendingProtocol = true
234234
235235 try {
236- options ?. log . trace ( 'optimistic: write ["%s", "%s", data] in source' , PROTOCOL_ID , protocol )
236+ options ?. log ? .trace ( 'optimistic: write ["%s", "%s", data] in source' , PROTOCOL_ID , protocol )
237237 await lp . writeV ( [
238238 uint8ArrayFromString ( `${ PROTOCOL_ID } \n` ) ,
239239 uint8ArrayFromString ( `${ protocol } \n` )
240240 ] )
241- options ?. log . trace ( 'optimistic: wrote ["%s", "%s", data] in source' , PROTOCOL_ID , protocol )
241+ options ?. log ? .trace ( 'optimistic: wrote ["%s", "%s", data] in source' , PROTOCOL_ID , protocol )
242242 } finally {
243243 sentProtocol = true
244244 sendingProtocol = false
@@ -255,15 +255,15 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
255255 readingProtocol = true
256256
257257 try {
258- options ?. log . trace ( 'optimistic: reading multistream select header' )
258+ options ?. log ? .trace ( 'optimistic: reading multistream select header' )
259259 let response = await multistream . readString ( lp , options )
260- options ?. log . trace ( 'optimistic: read multistream select header "%s"' , response )
260+ options ?. log ? .trace ( 'optimistic: read multistream select header "%s"' , response )
261261
262262 if ( response === PROTOCOL_ID ) {
263263 response = await multistream . readString ( lp , options )
264264 }
265265
266- options ?. log . trace ( 'optimistic: read protocol "%s", expecting "%s"' , response , protocol )
266+ options ?. log ? .trace ( 'optimistic: read protocol "%s", expecting "%s"' , response , protocol )
267267
268268 if ( response !== protocol ) {
269269 throw new CodeError ( 'protocol selection failed' , 'ERR_UNSUPPORTED_PROTOCOL' )
@@ -279,7 +279,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
279279 // make sure we've done protocol negotiation before we read stream data
280280 await negotiate ( )
281281
282- options ?. log . trace ( 'optimistic: reading data from "%s" stream' , protocol )
282+ options ?. log ? .trace ( 'optimistic: reading data from "%s" stream' , protocol )
283283 yield * lp . unwrap ( ) . source
284284 } ) ( )
285285
@@ -291,7 +291,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
291291 // this before closing the readable end of the stream
292292 if ( ! negotiated ) {
293293 await negotiate ( ) . catch ( err => {
294- options ?. log . error ( 'could not negotiate protocol before close read' , err )
294+ options ?. log ? .error ( 'could not negotiate protocol before close read' , err )
295295 } )
296296 }
297297
@@ -308,7 +308,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
308308 // this before closing the writable end of the stream
309309 if ( ! negotiated ) {
310310 await negotiate ( ) . catch ( err => {
311- options ?. log . error ( 'could not negotiate protocol before close write' , err )
311+ options ?. log ? .error ( 'could not negotiate protocol before close write' , err )
312312 } )
313313 }
314314
0 commit comments