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

  • Home
  • SEARCH
  • 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 5945487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:41:19+00:00 2026-05-22T16:41:19+00:00

https://github.com/saucelabs/monocle The following code is given as an example of standard event driven programming:

  • 0

https://github.com/saucelabs/monocle

The following code is given as an example of standard event driven programming:

def get_cmd(conn):
    conn.read_until("\n", callback=handle_cmd)

def handle_cmd(conn, cmd):
    if cmd.type == "get-address":
        # keep track of the conn so we can write the response back!
        def callback(result):
            handle_user_query_result(conn, result)
        db.query(cmd.username, callback)
    else:
        conn.write("unknown command")

def handle_user_query_result(conn, user):
    conn.write(user.address)

Though I don’t understand why a closure was needed. “keep track of the conn” contradicts how the first function “get_cmd” worked. Also, don’t event driven frameworks usually let you pass parameters around?

I’m guessing this would have been a more legitimate example:

def get_cmd(conn):
    conn.read_until("\n", callback=handle_cmd)

def handle_cmd(conn, cmd):
    if cmd.type == "get-address":
        db.query(cmd.username, callback=handle_user_query_result, params=conn)
    else:
        conn.write("unknown command")

def handle_user_query_result(result, params):
    user = result
    conn = params
    conn.write(user.address)

Am I wrong?

  • 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-05-22T16:41:19+00:00Added an answer on May 22, 2026 at 4:41 pm

    I’d say it’s a poor example because it doesn’t show just how bad callback-based event programming can be. The closure isn’t necessary, but it (presumably) is used to keep things logically organized, making the code easier to read/reason about. It’s quite common to write your callback as a closure. The whole point of the example is to illustrate how avoiding callbacks can make code more concise, arguably easier to read/write/reason about. Personally I’m not a fan of callback based programming, having used twisted and node.js a fair bit recently. Go write an application with either and then you’ll appreciate monocle’s approach (or not, some people prefer the callback-based approach).

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

Sidebar

Related Questions

Given the following plugin: https://github.com/Marak/jquery.emoticon.js How does the author expect you to use the
The installation for clearance seems very straight forward ( https://github.com/thoughtbot/clearance ). I'm following in
while running this example https://github.com/JakSprats/node_Redisql/blob/master/examples/redisql_examples.js gives me this error , ~/rahul$ node redissql.js node.js:178
in the rails source : https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb the following can be seen @load_hooks = Hash.new
I'm following this Hiphop installation guide: https://github.com/facebook/hiphop-php/wiki/Building-and-installing-on-ubuntu-10.10 And when I try to make it,
(NOTE: Source code here https://github.com/cthielen/dss-evote ) I've got a simple voting application. A survey
I am using the MWFeedParser (found here: https://github.com/mwaterfall/MWFeedParser ). I followed his example app,
Following the instructions here: https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows ) I've tried installing on two machines, either of
https://github.com/jmettraux/rufus-scheduler states that: rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs).
I am using https://github.com/feelinglucky/php-readability and I am able to get the author's example to

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.