@@ -93,29 +93,31 @@ func (o *operationMap) delete(name string) {
9393 o .mtx .Unlock ()
9494}
9595
96+ type Option func (conn * connection )
97+
9698// ReadLimit limits the maximum size of incoming messages
97- func ReadLimit (limit int64 ) func ( conn * connection ) {
99+ func ReadLimit (limit int64 ) Option {
98100 return func (conn * connection ) {
99101 conn .ws .SetReadLimit (limit )
100102 }
101103}
102104
103105// WriteTimeout sets a timeout for outgoing messages
104- func WriteTimeout (d time.Duration ) func ( conn * connection ) {
106+ func WriteTimeout (d time.Duration ) Option {
105107 return func (conn * connection ) {
106108 conn .writeTimeout = d
107109 }
108110}
109111
110112// Connect implements the apollographql subscriptions-transport-ws [email protected] 111113// https://github.com/apollographql/subscriptions-transport-ws/blob/v0.9.4/PROTOCOL.md
112- func Connect (ctx context.Context , ws wsConnection , service GraphQLService , options ... func ( conn * connection ) ) func () {
114+ func Connect (ctx context.Context , ws wsConnection , service GraphQLService , options ... Option ) func () {
113115 conn := & connection {
114116 service : service ,
115117 ws : ws ,
116118 }
117119
118- defaultOpts := []func ( conn * connection ) {
120+ defaultOpts := []Option {
119121 ReadLimit (4096 ),
120122 WriteTimeout (time .Second ),
121123 }
@@ -202,7 +204,7 @@ func (conn *connection) addSubscription(ctx context.Context,
202204 case <- t :
203205 // setup timed out
204206 ops .delete (message .ID )
205- ep := errPayload (errors . New ( " subscription connect timeout" ))
207+ ep := errPayload (fmt . Errorf ( "server subscription connect timeout after %s" , conn . writeTimeout ))
206208 send (message .ID , typeError , ep )
207209 send (message .ID , typeComplete , nil )
208210 kill <- true
0 commit comments