| SourceUnfoldResourceT, TSource Method |
Start a new
SourceTOut, TMat from some resource which can be opened, read and closed.
Interaction with resource happens in a blocking way.
Example:
{{{
Source.unfoldResource(
() => new BufferedReader(new FileReader("...")),
reader => Option(reader.readLine()),
reader => reader.close())
}}}
You can use the supervision strategy to handle exceptions for
read function. All exceptions thrown by
create
or
close will fail the stream.
Restart supervision strategy will close and create blocking IO again. Default strategy is
Stop which means
that stream will be terminated on error in `read` function by default.
You can configure the default dispatcher for this Source by changing the `akka.stream.blocking-io-dispatcher` or
set it for a given Source by using
CreateDispatcher(String).
Namespace:
Akka.Streams.Dsl
Assembly:
Akka.Streams (in Akka.Streams.dll) Version: 1.2.3.129 (1.2.3.129)
Syntax public static Source<T, NotUsed> UnfoldResource<T, TSource>(
Func<TSource> create,
Func<TSource, Option<T>> read,
Action<TSource> close
)
static member UnfoldResource :
create : Func<'TSource> *
read : Func<'TSource, Option<'T>> *
close : Action<'TSource> -> Source<'T, NotUsed>
Parameters
- create
- Type: SystemFuncTSource
function that is called on stream start and creates/opens resource. - read
- Type: SystemFuncTSource, OptionT
function that reads data from opened resource. It is called each time backpressure signal
is received. Stream calls close and completes when read returns None. - close
- Type: SystemActionTSource
TBD
Type Parameters
- T
- TBD
- TSource
- TBD
Return Value
Type:
SourceT,
NotUsedTBD
See Also