openOn static method
Future<Result<(NativeWorker, int), DbError> >
openOn(
- NativeSymbols symbols,
- String path,
- String options
Opens <path>.lmdb with options (JSON) on a running worker of
symbols: answers the worker and the handle, or the error the engine
answered (such as DbErrorCode.legacyFormat).
Implementation
static Future<Result<(NativeWorker, int), DbError>> openOn(
NativeSymbols symbols,
String path,
String options,
) async {
final worker = await of(symbols);
// A worker that stopped meanwhile is no longer listed: ask again.
if (worker._stopped) {
return openOn(symbols, path, options);
}
return (await worker._call('open', [path, options])).flatMap(
(reply) => switch (reply) {
[0, final String response] => ProtocolEnvelope.decode(response).flatMap(
(payload) => Err(
DbError(
DbErrorCode.unsupportedProtocol,
'The engine opened nothing but answered $payload',
),
),
),
[final int handle, String()] => Ok((worker, handle)),
_ => Err(_malformed(reply)),
},
);
}