@@ -464,44 +464,42 @@ localPort socket = do
464464 port <- runEffectFn1 localPortImpl socket
465465 pure (toMaybe port)
466466
467- foreign import onCloseServerImpl :: EffectFn2 Server (Effect Unit ) Unit
468-
469467-- | Attaches the callback as a listener to the `'close'` event.
470468-- |
471469-- | `'close'` is emitted when a close occurs.
472470-- | Will not be emitted until all connections have ended.
473471onCloseServer :: Server -> Effect Unit -> Effect Unit
474- onCloseServer server callback = runEffectFn2 onCloseServerImpl server callback
475-
476- foreign import onCloseSocketImpl :: EffectFn2 Socket (EffectFn1 Boolean Unit ) Unit
472+ onCloseServer server callback =
473+ runEffectFn3 onServerImpl " close" server callback
477474
478475-- | Attaches the callback as a listener to the `'close'` event.
479476-- | The `Boolean` represents whether an error happened during transmission.
480477-- |
481478-- | `'close'` is emitted when an close occurs.
482479onCloseSocket :: Socket -> (Boolean -> Effect Unit ) -> Effect Unit
483480onCloseSocket socket callback =
484- runEffectFn2
485- onCloseSocketImpl
481+ runEffectFn3
482+ onSocketImpl
483+ " close"
486484 socket
487485 (mkEffectFn1 \hadError -> callback hadError)
488486
489- foreign import onConnectImpl :: EffectFn2 Socket (Effect Unit ) Unit
490-
491487-- | Attaches the callback as a listener to the `'connect'` event.
492488-- |
493489-- | `'connect'` is emitted when a new connection is successfully establed.
494490onConnect :: Socket -> Effect Unit -> Effect Unit
495- onConnect socket callback = runEffectFn2 onConnectImpl socket callback
496-
497- foreign import onConnectionImpl :: EffectFn2 Server (EffectFn1 Socket Unit ) Unit
491+ onConnect socket callback = runEffectFn3 onSocketImpl " connect" socket callback
498492
499493-- | Attaches the callback as a listener to the `'connection'` event.
500494-- |
501495-- | `'connection'` is emitted when a new connection is made.
502496onConnection :: Server -> (Socket -> Effect Unit ) -> Effect Unit
503497onConnection server callback =
504- runEffectFn2 onConnectionImpl server (mkEffectFn1 \socket -> callback socket)
498+ runEffectFn3
499+ onServerImpl
500+ " connection"
501+ server
502+ (mkEffectFn1 \socket -> callback socket)
505503
506504foreign import onDataImpl :: EffectFn3 Socket (EffectFn1 Buffer Unit ) (EffectFn1 String Unit ) Unit
507505
@@ -517,79 +515,72 @@ onData socket callback =
517515 (mkEffectFn1 \buffer -> callback $ Left buffer)
518516 (mkEffectFn1 \str -> callback $ Right str)
519517
520- foreign import onDrainImpl :: EffectFn2 Socket (Effect Unit ) Boolean
521-
522518-- | Attaches the callback as a listener to the `'drain'` event.
523519-- |
524520-- | `'drain'` is emitted when the write buffer is empty.
525521onDrain :: Socket -> Effect Unit -> Effect Boolean
526- onDrain socket callback = runEffectFn2 onDrainImpl socket callback
527-
528- foreign import onEndImpl :: EffectFn2 Socket (Effect Unit ) Unit
522+ onDrain socket callback = runEffectFn3 onSocketImpl " drain" socket callback
529523
530524-- | Attaches the callback as a listener to the `'end'` event.
531525-- |
532526-- | `'end'` is emitted when the other end of the `Socket` sends a `FIN` packet.
533527onEnd :: Socket -> Effect Unit -> Effect Unit
534- onEnd socket callback = runEffectFn2 onEndImpl socket callback
535-
536- foreign import onErrorServerImpl :: EffectFn2 Server (EffectFn1 Error Unit ) Unit
528+ onEnd socket callback = runEffectFn3 onSocketImpl " end" socket callback
537529
538530-- | Attaches the callback as a listener to the `'error'` event.
539531-- |
540532-- | `'error'` is emitted when an error occurs.
541533onErrorServer :: Server -> (Error -> Effect Unit ) -> Effect Unit
542534onErrorServer server callback =
543- runEffectFn2 onErrorServerImpl server (mkEffectFn1 \error -> callback error)
544-
545- foreign import onErrorSocketImpl :: EffectFn2 Socket (EffectFn1 Error Unit ) Unit
535+ runEffectFn3
536+ onServerImpl
537+ " error"
538+ server
539+ (mkEffectFn1 \error -> callback error)
546540
547541-- | Attaches the callback as a listener to the `'error'` event.
548542-- |
549543-- | `'error'` is emitted when an error occurs.
550544-- | `'close'` is emitted directly after this event.
551545onErrorSocket :: Socket -> (Error -> Effect Unit ) -> Effect Unit
552546onErrorSocket socket callback =
553- runEffectFn2 onErrorSocketImpl socket (mkEffectFn1 \error -> callback error)
554-
555- foreign import onListeningImpl :: EffectFn2 Server (Effect Unit ) Unit
547+ runEffectFn3 onSocketImpl " error" socket (mkEffectFn1 \err -> callback err)
556548
557549-- | Attaches the callback as a listener to the `'listening'` event.
558550-- |
559551-- | `'listening'` is emitted when the `Server` has been bound.
560552onListening :: Server -> Effect Unit -> Effect Unit
561- onListening server callback = runEffectFn2 onListeningImpl server callback
562-
563- foreign import onLookupImpl :: EffectFn2 Socket (EffectFn4 (Nullable Error ) (Nullable String ) (Nullable (Nullable Int )) (Nullable String ) Unit ) Unit
553+ onListening server callback =
554+ runEffectFn3 onServerImpl " listening" server callback
564555
565556-- | Attaches the callback as a listener to the `'lookup'` event.
566557-- |
567558-- | `'lookup'` is emitted after resolving the hostname but before connecting.
568559onLookup :: Socket -> (Either Error Lookup -> Effect Unit ) -> Effect Unit
569560onLookup socket callback =
570- runEffectFn2 onLookupImpl socket $ mkEffectFn4 \err' address'' family' host' ->
561+ runEffectFn3 onSocketImpl " lookup " socket $ mkEffectFn4 \err' address'' family' host' ->
571562 case toMaybe err', toMaybe address'', toMaybe family', toMaybe host' of
572563 Just err, _, _, _ -> callback (Left err)
573564 Nothing , Just address', Just family, Just host ->
574565 callback (Right { address: address', family: toMaybe family, host })
575566 _, _, _, _ -> mempty
576567
577- foreign import onReadyImpl :: EffectFn2 Socket (Effect Unit ) Unit
578-
579568-- | Attaches the callback as a listener to the `'ready'` event.
580569-- |
581570-- | `'ready'` is emitted when the `Socket` is ready to be used.
582571onReady :: Socket -> Effect Unit -> Effect Unit
583- onReady socket callback = runEffectFn2 onReadyImpl socket callback
572+ onReady socket callback = runEffectFn3 onSocketImpl " ready" socket callback
573+
574+ foreign import onServerImpl :: forall f . EffectFn3 String Server (f Unit ) Unit
584575
585- foreign import onTimeoutImpl :: EffectFn2 Socket (Effect Unit ) Unit
576+ foreign import onSocketImpl :: forall a f . EffectFn3 String Socket (f Unit ) a
586577
587578-- | Attaches the callback as a listener to the `'timeout'` event.
588579-- |
589580-- | `'timeout'` is emitted if the `Socket` times out from inactivity.
590581-- | The `Socket` is still open and should be manually closed.
591582onTimeout :: Socket -> Effect Unit -> Effect Unit
592- onTimeout socket callback = runEffectFn2 onTimeoutImpl socket callback
583+ onTimeout socket callback = runEffectFn3 onSocketImpl " timeout " socket callback
593584
594585foreign import pauseImpl :: EffectFn1 Socket Unit
595586
0 commit comments