2013/12/01

Futures advent day 1

It is traditional around this time of year for Perl blogs to publish an advent calendar - a series of 24 short little posts around a common theme.

People have suggested I might write one about Futures, so here goes...

Day 1 - Futures can return values synchronously

You don't in fact have to use a Future for anything asynchronous. A simple synchronous-returning function can use them too.

use Future;

sub sum
{
   my @numbers = @_;
   my $total = 0;
   $total += $_ for @numbers;
   return Future->new->done( $total );
}

say "The total is " . sum( 10, 20, 30 )->get;

It may not be immediately obvious currently why you want to do this, but I hope to motivate why over the following 23 posts...

<< First | < Prev | Next >

4 comments:

  1. Fascinating! But where did the "get" method come from?

    ReplyDelete
  2. I'm presuming Future has a get method on it to resolve it?

    http://search.cpan.org/~pevans/Future-0.20/lib/Future.pm#$result_=_$future->get

    ReplyDelete
  3. TOTO988,date merupakan Situs Judi Online Terlengkap dan Terpercaya.
    Hanya Dengan 1 Akun Sudah Bisa Main Semua Games Populer.

    Link Alternatif = www.TOTO988.pro

    Tersedia Game:
    -Togel
    -Poker
    -Domino
    -Bola/Sportbook
    -Sabung Ayam
    -Casino
    -Tangkas
    -Slot Games
    -Bola Gelinding
    -Tembak Ikan
    -Batu Goncang
    -dan masih banyak Games seru lainnya.

    Fasilitas :
    ~ Minimal Depo & Wede hanya Rp 20.000
    ~ Proses Depo & Wede Cepat & Mudah.
    ~ CS Profesional Online 24 Jam.
    ~ Sistem E-Wallet (1 Akun main semua Game).
    ~ Games Lengkap & Anti Lelet.
    ~ Bonus Terbesar dan Terbanyak.
    ~ Pasaran Odds & Diskon Terbesar.

    Promo Bonus:
    -Bonus Deposit Harian 5%.
    -Bonus Rollingan 0,25% (Bola).
    -Bonus Rollingan 0,8% (Casino).
    -Bonus Rollingan 0,25% (Sabung Ayam).
    -Bonus Rollingan 0,3% (Poker & Domino).
    -Bonus Cashback 15% (Bola).
    -Bonus Cashback 10% (Casino).
    -Bonus Cashback 20% (E~Games).
    -Bonus Cashback 15% (Sabung Ayam).
    -Bonus Referral 3%.
    -Bonus Referral 3%.

    Untuk Info Promo Bonus TOTO988 hub:
    BBM : D8A562CA / TOTO988
    WA : +85515289210

    poker idn
    bandar togel online
    togel terpercaya
    situs togel online
    agen idn
    togel hongkong
    promo togel
    diskon togel terbesar

    ReplyDelete