►
From YouTube: Rust Hungary - Meetup S03 E02
Description
00:00 Introduction
02:15 Balázs Söptei: Async programming in Rust & the Actix framework
- Slides: https://docs.google.com/presentation/d/15C3SiahvPhGxOMSn2v90jeHylqlcPk1n5PNtYuh27vU/view
Meetups are streamed live on https://meetup.rustl-lang.hu
A
A
We
have
organized
rust
fests
as
well,
but
we
participated
in
paris
and
in
rome
too,
and
unfortunately,
we
have
no
rescue
jobs
yet,
but
if
you
are
interested
in
other
jobs,
you
can
find
hours
on
memox.com,
slash
jobs
or
if
you
have
any
questions
or
need
some
help
about
your
it
carrier.
We
can
help
you
too
contact
us
well
with
our
website.
A
A
You
can
remember
him
from
one
of
the
presenter
of
9
20
90
last
meetups
in
this
presentation.
He
would
like
to
show
two
things,
and
one
is
he's
a
scene
programming
in
glass.
The
other
one
is
the
active
framework
which
makes
it
easy
to
develop
as
in
web
applications.
A
He
will
demonstrate
the
topic
via
data
store,
updates
on
the
framework
communicating
through
the
protocol
yeah
during
the
meetup.
You
can
ask
from
balaj
in
our
matrix
group,
and
you
know
the
link
was
sent
yesterday
via
email
and
after
the
presentation
you
will
have
time
to
cheat
chat
on
june
link
will
be
sent
by
us
during
the
presentation.
B
B
Here
I'm
going
to
be
scratching
the
surface,
but
I'm
going
to
recommend
some
websites
and
documentation
if
you
want
to
read
further
in
any
parts
of
of
the
topics,
so
I
have
divided
this
stock
into
three
major
parts.
Part
one
is
async
await
part
two
is
actix
web
and
part
three.
I
am
going
to
demo
my
toy
project,
which
is
an
async
web
server
based
on
the
actics
web
framework.
B
B
B
Another
one
is
called
co
routines.
They
are
present
in
kotlin
and
the
go
language
and
in
the
letter
they
are
even
called
go
routines
with
the
g,
so
they
have
a
funny
name
and
the
third
one
I'm
mentioning
here
are
callbacks.
B
B
Let's
see
what
this
represents
first,
so
this
in
this
model,
these
tasks
are
computed
or
executed
one
after
another,
and
these
color
rectangles
not
only
represent
the
time
spent
with
the
calculation,
but
they
also
represent
time
waiting
this
so
the
program
or
the
thread
is
waiting
for
a
task
to
complete.
B
The
whole
idea
is
to
enable
the
thread
or
the
program
make
useful
work,
while
it
is
waiting
for
a
task
to
complete.
So
you
can
see
it
starts
with
the
green
test
task
one
and
when
it
cannot
progress,
it
switches
to
another
task
and
so
on
so
and
well
the
so.
The
whole
idea
is
that
you
don't
do
not
wait
in
ways,
so
the
program
does
not
waste
time
it.
It
can
do
something
useful
while
one
task
needs
to
complete.
B
Okay,
next
thing
I
would
like
to
talk
about
is
the
async
and
the
await
keywords
in
rus
and
the
future
trade
from
I,
if
I
remember
well
from
arrest
version,
1.39,
the
async
and
the
await
keywords
are
stable,
so
you
can
use
them
in
stable
rest
and
the
keyword
async.
It
provides
syntactic
sugar,
I'm
going
to
show
you
an
example
what
it
does
okay,
so
you
can
use
the
async
keyword
and
you
make
the
function
or
block
or
closure
return
a
future.
B
The
only
thing
I
would
like
to
mention
here
is
that
a
future
represent
a
task
that
may
have
not
completed
yet
it
will
complete
sometime
later,
if
it's
not
completed
yet,
and
as
I
mentioned
before,
the
idea
is
to
enable
the
thread
or
program
do
useful
work,
while
it
waits
for
a
test
complete.
So
it
can
switch
between
tasks
that
are
asynchronous
okay,
async
keyword,
you
can
mark
functions
with
async.
B
B
One
thing
I
would
like
to
mention
here
that
in
trades
the
async
functions
are
not
yet
supported
in
the
standard
library,
but
there
is
a
crate
called
async
trade
which
enables
that.
However,
the
async
book
says
that
the
async
trade
comes
with
heap
allocation,
so
you
might
want
to
consider
that
when,
when
using
it,
so
it
has
a
performance
cost.
B
B
Do
something:
okay,
the
one
rule
is
that
you
can
use
the
weight
keyword
only
in
async
functions
or
blocks,
or
closures,
oops,
okay,
one
other
thing
I
would
like
to
mention
here
is
that,
in
order
to
make
futures
work,
you
will
need
an
executor
or
in
other
words
you
will
need
a
runtime
and
the
rust
standard
library
doesn't
have
a
built-in
runtime.
B
However,
there
are
crates
that
provide
runtimes
for
executing
and
computing
futures
and
asynchronous
tasks,
and
the
async
book
mentions
a
bunch
of
them
and
if
you
don't
like
those
provided
runtimes
provided
by
creates,
you
can
implement
your
own.
B
So
I
have
some
silly
examples:
these
are
very
simple
pieces
of
code
just
to
make
a
point,
and
I
have
it
on
github.
However,
I
copied
and
pasted
it
into
the
play,
browse
playground
so
and-
and
I
can
show
you
some
examples
of
of
asynchronous
things.
As
I
mentioned,
there
is
no
built-in
runtime
in
rust.
B
For
example,
there
is
something
in
the
futures
crate.
I
am
going
to
use
this
block
on
function
as
a
workaround.
You
will
see
why
I'm
using
it
one.
The
first
thing
I
would
like
to
show
you
is
this
syntax,
so
you
are
using
the
async
keyword
here
in
this
function.
Definition-
and
you
say
it
returns
a
u64,
but
actually
what
it
returns
is
a
feature
of
a
u64.
B
B
So
if
you
don't
want
to
use
the
async
keyword,
you
can
use
a
function,
a
a
regular
function
and
make
it
return
a
something
that
implements
a
future,
the
output
type
of
which
is
a
u64
okay.
The
body
is
not
quite
equivalent,
but
it's
it's
simplification.
It's
already
function
it.
It
represents
a
feature
that
is
ready
on
the
spot.
B
Actually,
actually
async
functions
have
some
compiler
magic
under
the
hood
so
and
I'm
going
to
show
you
that
the
two
functions
return:
the
same
output,
I'm
asserting
the
equality
here
in
line
43,
and
you
can
see
it
run
without
errors
and
I'm
using
this
block
home
because
the
regular
main
function
cannot
be
marked
as
asynchronous.
B
Okay,
so
the
next
thing
I
would
like
to
show
is
that
the
futures
are
lazy,
as
I
mentioned,
so
here's
an
asynchronous
function
that
panics
in
the
body,
so
it
throws
an
error,
but
if
you
don't
await
this
function,
if
you
don't
drive
it
into
completion,
then
it
won't
panic
so
because
it
it's
not
a
simple
function,
it
returns
a
future.
So
the
type
of
this
is
a
future
unit
or
future
void.
B
B
So,
for
example,
there's
this
trade
called
future
extensions
and
it
provides
a
handful
of
other
adapters,
one
of
which
is
maps,
so
it
takes
a
future
and
with
the
map
function
you
can
take
provide
a
a
closure
that
takes
the
result
of
the
future
and
pro
processes
for
it
further,
and
this
incremented
square
is
still
a
future.
B
B
Feature
script
also
has
macros
that
help
with
the
control
flow.
So
here
we
have
this
macro
called
join
and
the
documentation
says
that
it
pulls
multiple
futures
simultaneously,
and
here
comes
the
power
of
asynchronous
computation.
So
it's
much
much
more
powerful
than
just
simply
awaiting
them,
one
after
another,
because
it
says
that
they
are
pulled
simultaneously.
B
And
this
macro
can
also
be
used
only
in
async
functions,
racing
blocks.
As
I
mentioned,
there
is
in
blocks
and
I
will
show
an
example.
This
is
one,
so
you
just
simply
write
async
and
you
can
do
some
asynchronous
logic
in
within
the
curly
braces
and
the
whole
thing
returns
a
future
and
I
can
block
it.
B
B
B
B
B
Okay,
next
thing
I
would
like
to
show
you
is
a
benchmark
of
synchronous
versus
asynchronous
mechanism
or
model
in
code,
so
I
made
this.
B
Program
that
does
a
linear
regression,
so
it
it
takes
a
series
of
data
points
and
it
constructs
a
linear
model
from
those
data
points
here
I
have
a
sequential
implementation,
so
this
function
is
not
asynchronous.
It
just
calculates
the
necessary
data
for
the
regression
one
after
another
and
in
the
end
it
returns
a
linear
model.
B
B
There
are
some
pieces
of
data
that
do
not
depend
on
each
other,
so
they
can
be
calculated
independently
and
they
can
be
calculated
by
using
the
joint
macro.
So
they
can
be
pulled
simultaneously,
and
there
is
another
point
that
where
this
can
be
done,
this
to
the
kind
that
don't
depend
on
each
other,
so
they
can
be
run
asynchronously
independently
and
again
they
can
be
pulled
simultaneously.
Using
the
join
macro
and
the
output
is
is
the
same.
B
Okay,
so
the
thing
I
did
using
this,
these
two
functions
is
that
I
run
a
benchmark
using
the
criterion
crate.
B
And
I
have
the
source
in
this
benchmarks
benchmarks.rs,
so
I'm
using
criterion
that
supports
asynchronous
executing
during
benchmarks,
and
I
have
a
data
point
series
that
is
a
size
of
1
million
and
I
provided
both
functions
with
this
input
and
I
measured
the
time
using
criteria.
I'm
going
to
enlarge
this
a
bit
so.
B
This
is
the
synchronous
or
sequential
model.
What
you
need
to
see
is
the
mean
estimate
and
the
this
is
around
24
milliseconds.
B
For
a
million
of
data
points,
and
compared
to
that,
I
have
the
asynchronous
version
that
have
16
point.
Something,
and
what
I
like
to
emphasize
here
is
that
not
not
the
absolute
value
is
that
counts
here,
but
the
difference
between
the
model.
B
Okay,
here's
it
with
a
simple
measurement
to
demonstrate
this,
and
if
you
would
like
to
re
reproduce
it
you
can
navigate
to
this
github
repo
and
and
clone
it
and
run
your
own
measurements.
B
B
B
Okay,
so
I
mentioned
this
is
a
toy
project
which
operates
with
an
in-memory
store
and
this
store
can
be
replaced
with
an
actual
database
connection.
However,
if
you
want
to
further
develop
this,
but
what
this
store
actually
looks
like
is
that
it's
a
trait
and
it
it
supports
basic,
create,
read,
update,
delete
operations,
as
I
mentioned,
you
can
only
use
async
functions
in
trades
with
with
some
workarounds
with
one
of
which
is
the
async
trade,
and
it
has
some
performance
costs.
B
B
What
I'm
configuring
here
are
the
end
points
and
the
endpoints
look
like
this.
So
basically,
we
have
two
kinds
of
urls.
One
is
the
simple
dash
data
and
the
other
one
is
dash
data
dash
key,
which
in
here
key,
is
a
placeholder.
It's
a
pattern
and
you
can
extract
the
key,
which
represents
a
key
in
the
data
store
itself.
B
B
B
B
B
B
You
can
call
this
endpoint
with
any
kind
of
key
and
this
key
is
extracted,
and
that
is
the
functionality
of
this
path
of
of
the
framework
and
it's
type
safe.
So
the
type
of
key
is
you
size?
If
I
remember
well,
so
it
extracts
the
key
and
passes
on
to
the
handler
function.
B
Another
thing
is,
the
store
is
in
this
function,
notation
and
it
is
wrapped
inside
this
web
data,
which
is,
as
I
mentioned,
is
responsible
for
for
shared
data.
So
this
is
shared
data
and,
in
this
handler
functions
operate
on
the
data
by
delegating
it
to
the
delegating
the
functionality
to
to
the
data
store.
B
Okay,
I
believe
I'm
using
only
the
js
and
the
pass
and
the
data
the
framework
provides
more
than
that,
so
the
actix
web
framework
has
other
kinds
of
extractors
such
as
a
web
form.
You
can
pass
on
the
results
of
web
forms
via
that.
B
So
the
framework
provides
a
handful
of
http
responses.
I
think
this
project
operates
with
okay
responses,
most
of
the
time,
because
it's
a
toy
project,
but
you
have
these
methods
that
correspond
to
most
of
the
commonly
used
http
responses
response
codes.
B
Okay,
so
basically,
this
is
what
this
toy
application
does.
The
framework,
however,
provides
a
much
much
more
that
you
can
use.
So,
for
example,
you
can
serve
static
files,
you
can
pre
and
post
process
the
requests.
I
mean
you
can
pre-process
the
requests
and
post
processor
responses,
and
I
will
I
will
show
you
a
link
to
the
hectic's
official
website
and
you
can
read
it
and
you
can
experiment
with
it
for
your
own
purposes.
B
B
This
is
a
powerful
feature
of
the
framework.
Another
powerful
feature
is
that
you
can
use
a
test
service
and
configure
a
test
application
there,
and
you
can
send
test
responses
test
request,
sorry
to
do
this
test
application
and
do
assertions
on
the
responses
that
it
provides
based
on
your
requests,
so
you
can
test
the
whole
application
test.
All
the
end
points
without
having
to
run
around
your
application.
B
B
I
have
this
toy
project
on
github,
here's
the
link,
so
you
can
watch
that
you
can
examine
the
code
and
you
can
fork
it
and
clone
it
and
and
play
around
with
it
if
you
want
to
in
your
free
time
and
here's
the
link
to
the
acting's
official
website,
it's
a
really
well
documented
framework.
So
here
you
have
a
handful
of
examples
that
can
help
you
get
started.
B
Okay,
now
we
have
arrived
to
part
three
and
I'm
going
to
demonstrate
this
toy
project
of
mine,
see
what
you
can
see
here
I
will
represent.
I
will
demonstrate
it
right
away,
so
I
have
deployed
this
application
to
heroku
and
now
I'm
going
to
wake
it
up,
because
it
runs
on
three
dinos
that
are
asleep
currently,
and
here
you
can
see
the
application
runs
properly,
which
means
we
can
now
test
it.
B
B
B
B
I
will
send
a
get
request
for
this
data
endpoint
and
it
it's
going
to
return
a
an
array
which
currently
has
a
single
piece
of
data,
and
here
I
have
the
key-
and
I
can
take
this
key
and
copy
it
and
paste
it
here
so
like
if
we
just
makes
it
possible
to
query
the
data
one
by
one.
So
if
I
turn
this
response,
it
returns
the
single
one
based
on
the
key.
B
B
B
Basically,
and
as
I
mentioned,
so
it's
not
it's
not
meant
for
production
purposes,
but
it
demonstrates
well
how
easy
it
is
to
to
create
a
web
server
using
the
actix
web
framework
and
you
can
play
around
with
it
and
you
can
replace
the
in-memory
store
with
an
actual
one.
If
you
want
to
use
it
for
actual
data
store
purposes,.
B
Okay,
so
I
have
arrived
to
the
summary
so
in
this
talk
I
have
shown
you
the
surface
of
the
async,
await
keywords
and
the
future
trading
rust
how
to
use
it,
what
you
can
do
with
it
the
power
it
has-
and
I
have
demonstrated
the
features
of
the
actix
web
framework
using
a
toy
project
of
mine,
which
is
a
in-memory
data
store
running
based
on
the
actics
web
framework.
B
B
As
I
mentioned,
I
have
my
code
examples
on
github,
so
these
are.
These
are
the
examples
I've
shown
in
the
in
the
playground.
These
are
just
silly
examples
to
make
a
point.
These
are
not
very
useful,
so
this
is
much
more
useful
because
it
shows
how
you
can
leverage
the
powers
of
asynchrony
and
you
can
and
how
to
benchmark
using
the
criterion
crate,
and
here
I
have
the
github
link
for
the
repo
for
my
toy
project.
B
A
Sorry,
sorry,
so
thank
you
so
much
for
the
great
talk
that
was
the
second
stock
of
the
year
and
the
next
one
will
be
on
the
29th
of
april
and
you
can
schedule
on
meetup.com
as
well.
So
you
can.