-
Notifications
You must be signed in to change notification settings - Fork 8
Abe Pralle edited this page Sep 7, 2022
·
6 revisions
use v1=resource_provider_1 [, v2=resource_provider_2, ...]
...
endUse
- At its core ,
use
assigns resources to local variables within the scope of theuse
command. - If an assigned variable already exists, its value is preserved and restored at the
endUse
command. - The resource must implement the Use Protocol, described below.
use
will automatically call the following methods on a resource provider:
Writing use v = resource_provider
becomes local v = resource_provider.on_use()
.
Returns the acquired resource to the provider.
- The used resource will be correctly released if there are any returns, escapes, or exceptions thrown within the
use
statements.
use builder = String.pool
builder.print "Hello World!"
println builder
endUse
# Equivalent to
local provider = String.pool
local builder = provider.on_use
builder.print "Hello World!"
println builder
provider.on_end_use( builder )