BT

InfoQ Homepage Research How Do You Handle Async APIs and Callback Hell?

How Do You Handle Async APIs and Callback Hell?

Bookmarks

InfoQ's research widget has been deprecated. It should continue to work however, and we hope to relaunch it at some point in the future.

While asynchronous APIs can bring advantages, they certainly complicate programming by forcing developers to manually string together sequential operations using callbacks, causing a phenomenon called "Callback Hell".

The increasing popularity of asynchronous APIs, partially due to the rise of JavaScript and Node.js, means that many developers are now faced with a prolonged stay in Callback Hell. As is usual, developers with enough of an itch will find a way to scratch it. In the case of Callback Hell, there's a rich supply of hacks, workarounds, and solutions.

InfoQ wants to know: how do you handle asynchronous APIs? How do you stay out of Callback Hell or how do you manage it?

Language features and related

These are solutions that are either straight up language features or are supported by language features (eg. macros, etc).

Extensions of the language runtime or bytecode

Libraries

  • Reactive Extensions (Rx)
    An increasingly popular approach that started on .NET and has been ported to other platforms including Java and JavaScript. As an example, Netflix is behind the Java port RxJava; see Netflix' Ben Christensen interview on RxJava.
  • Promises or Futures
    Promises (and their namesakes) have been adopted by many (standard) libraries and make it easier to chain operations. 
  • Embedded DSL-style libraries
    Libraries that allow one to chain statements, often using Promises underneath, are particularly popular in JavaScript.

Misc

  • State machines
    Using libraries like ignite.js, Ragel, etc.
  • Just write callbacks!
    Is "Callback Hell" just bad developers complaining about their tools? Do you just grit your teeth and nest your callbacks rather spend weeks researching alternative solutions?
  • Synchronous APIs
    Do you avoid asynchronous APIs at all costs? 

Note: if we missed your favorite language, library or solution, please tell us about it in the comments. 

 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • What other language with lightweight threads?

    by Yichao Zhang /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    If that other language is Erlang, then I think it's quite mature and widely adopted.

  • Protothreads

    by John Carter /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    At the intersection of light weight threads, C, evil abuses of language standards and state machines there exists Protothreads.

    dunkels.com/adam/pt/

  • Law of Demeter

    by John Carter /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Actually, call back hell is a code smell.

    It's a stench of a Law of Demeter Violation in progress.

    The solution is to Tell, don't Ask.

  • We use kontraktor :-)

    by Rüdiger Möller /

    Your message is awaiting moderation. Thank you for participating in the discussion.

  • Re: Law of Demeter

    by Ted Slusser /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I'll Ask you to Tell me more about it :)

  • bad poll

    by Rüdiger Möller /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    You should abstract out general patterns (e.g. actors, csp, traditional multithreading, lightweight mt). It mixes up implementations, language and methodology. There are many terminologies for identical models.

    check out this

    java-is-the-new-c.blogspot.de/2014/01/comparisi...

    java-is-the-new-c.blogspot.de/2014/06/java-conc...

  • Continuations?

    by Cameron Purdy /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Surprised that "continuations" was not one of the options.

  • Async API in Java

    by Zhong Yu /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Please also check out bayou Async API - bayou.io/release/0.9/docs/async/Async_Programmi...

  • Re: Continuations?

    by Mark Sasler /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Take a look at www.dragome.com, this tool is capable of avoiding callback hell using continuations.
    Its CallbackEvictor module works creating a proxy over invoked service, it pauses the application flow while is waiting the async reply and continue the execution when internal callback is executed with the expected result.
    It allows the use of continuations and dynamic proxies in javascript thanks to an automatic Java to Javascript conversion. Since this conversion is based in generated bytecode and not the source code, libraries such as Javaflow are used to achieved this.



    Surprised that "continuations" was not one of the options.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.