Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8218705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:53:39+00:00 2026-06-07T12:53:39+00:00

I am using the Pipes-2.1.0 package and the zeromq3-haskell package to construct a little

  • 0

I am using the Pipes-2.1.0 package and the zeromq3-haskell package to construct a little message pipeline. Everything seems to be going well except that I am having trouble understanding finalization of Frames.

In the following Frame I acquire two resources; a zeromq context, and a zeromq socket. Then I continuously wait for messages (in the form of ByteStrings) to publish on the zeromq socket.

{-# LANGUAGE RebindableSyntax    #-}
{-# LANGUAGE ScopedTypeVariables #-}

module PipesZeroMQ where

import           Control.Frame
import           Control.IMonad.Do
import           Control.IMonad.Trans
import qualified Control.Monad          as M
import           Data.ByteString        (ByteString)
import           Data.String
import           Prelude                hiding (Monad(..))
import qualified System.ZMQ3            as ZMQ

type Address = String

fromList :: (M.Monad m) => [b] -> Frame b m (M a) (M a) ()
fromList xs = mapMR_ yield xs

publisher :: Address -> Frame Void IO (M ByteString) C ()
publisher addr = do
  c  <- liftU $ ZMQ.init 1
  s  <-liftU $ ZMQ.socket c ZMQ.Pub
  liftU $ ZMQ.bind s addr   
  liftU $ print "Socket open for business!!!"

  foreverR $ do
    bs <- await
    finallyF (ZMQ.close s M.>> ZMQ.term c M.>> print "ZMQ socket closed") $ do
         (liftU $ ZMQ.send s [] bs)
         (liftU (print "Sending message"))

Now if I try this:

λ> runFrame $ (publisher localAddress) <-< (fromList ["This", "that", "that"] >> close)

I get this:

"Socket open for business"
"Sending message"
"ZMQ socket closed"
*** Exception: ZMQError { errno = 88, source = "send", message = "Socket operation on non-socket" }

publisher finalizes after receiving but one BytesString.

Why is this happening?

What am I misunderstanding about finalization using Frames in Pipes-2.1.0?

Does the tree outside stand a chance if I start attacking it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:53:41+00:00Added an answer on June 7, 2026 at 12:53 pm

    You made a mistake when writing the publisher function:

    foreverR $ do
        bs <- await
        finallyF (ZMQ.close s M.>> ZMQ.term c M.>> print "ZMQ socket closed") $ do
             (liftU $ ZMQ.send s [] bs)
             (liftU (print "Sending message"))
    

    You probably wanted to place the finallyF OUTSIDE the foreverR loop:

    finallyF (...) $ foreverR $ do
        bs <- await
        liftU $ ZMQ.send s [] bs)
        liftU (print "Sending message")
    

    The way you wrote it, it finalizes after each send, so it’s doing exactly what you told it to do: finalize after every send. finallyF calls the finalizer once the action it wraps is complete, both if it terminates successfully or unsuccessfully. You could also use catchF in that case, since the loop never terminates anyway:

     catchF (...) $ foreverR $ do
        bs <- await
        liftU $ ZMQ.send s [] bs)
        liftU (print "Sending message")
    

    Alternatively, you could have kept it inside the loop but switched to catchF so that the finalizer doesn’t get run after each send:

    foreverR $ do
        bs <- await
        catchF (ZMQ.close s M.>> ZMQ.term c M.>> print "ZMQ socket closed") $ do
             (liftU $ ZMQ.send s [] bs)
             (liftU (print "Sending message"))
    

    Also, if you are planning on writing a zeroMQ library based on pipes, keep in touch with me because I’m planning to return frames back to an ordinary monad in the next release with a lot of new enhancements to functionality, too, such as the ability to close and reinitialize resources. To reach me use my gmail.com address with username Gabriel439.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to update my twitter status using yahoo pipes. I could do that
I have tried to install Net::Arping package using cpan and I can't do that
I'm trying using pipes with boost libraries, I just want to execute a background
I'm trying to send and receive using pipes: send.cpp struct { long a; long
The subject line says it all. I'd also like to do this using pipes.
I remember using Named Pipes for communicating between 2 machines (back in Windows NT).
I'm using named pipes as the log file for the access_log of my nginx,
Lately I've been favoring using named pipes (option --enable-named-pipes) in MySQL running on windows,
I read an exec'd program's stdout using a pipe: int pipes[2]; pipe(pipes); if (fork()
I am using pipe to write a coprocess. The parent creates two pipes, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.