The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Dancer::Plugin::Async - Dancer plugin to write async request handlers with Twiggy


version 0.1


This plugin helps you to write async web applications (or partly async web apps) using Twiggy and Dancer. It provides the async keyword and a default Application that you can use with Plack.


In your lib/

    use Dancer::Plugin::Async;
    use AnyEvent;

    # Async request handler, responds when the timer triggers
    async 'get' => '/timer' => sub {
        my $respond = respond;

        my $t; $t = AnyEvent->timer(after => 1, cb => sub {
            $respond->([ 200, [], [ 'foo!' ]]);

    # Normal Dancer route handler, blocking
    get '/blocking' => sub {
        redirect '/timer';

In your bin/

    use Dancer;
    use Dancer::Plugin::Async;
    use Twiggy;
    use AnyEvent;
    use myapp;
    use EV;

    my $server = Twiggy::Server->new(
        host => '',
        port => 3000,




In the callbacks (for example of the timer in the SYNOPSIS), you cannot use many of the normal Dancer keywords such as template, redirect, etc. This is due to Dancer accessing Dancer::SharedData, which is not available later on. If anyone has a good idea on how to solve this problem, suggestions/patches are very welcome.


Michael Stapelberg, <michael at>


Please report any bugs or feature requests to bug-dancer-plugin-async at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Async

You can also look for information at:


Copyright 2010 Michael Stapelberg.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.