ensureStarted method
Future<Satellite>
ensureStarted({
- required DbName dbName,
- required DBSchema dbDescription,
- required DatabaseAdapter adapter,
- required Migrator migrator,
- required Notifier notifier,
- required SocketFactory socketFactory,
- required HydratedConfig config,
- SatelliteOverrides? opts,
inherited
Implementation
@override
Future<Satellite> ensureStarted({
required DbName dbName,
required DBSchema dbDescription,
required DatabaseAdapter adapter,
required Migrator migrator,
required Notifier notifier,
required SocketFactory socketFactory,
required HydratedConfig config,
SatelliteOverrides? opts,
}) async {
// If we're in the process of stopping the satellite process for this
// dbName, then we wait for the process to be stopped and then we
// call this function again to retry starting it.
final stoppingPromises = this.stoppingPromises;
final stopping = stoppingPromises[dbName];
if (stopping != null) {
return stopping.then(
(_) => ensureStarted(
dbName: dbName,
dbDescription: dbDescription,
adapter: adapter,
migrator: migrator,
notifier: notifier,
socketFactory: socketFactory,
config: config,
opts: opts,
),
);
}
// If we're in the process of starting the satellite process for this
// dbName, then we short circuit and return that process. Note that
// this assumes that the previous call to start the process for this
// dbName would have passed in functionally equivalent `dbAdapter`,
// `fs` and `notifier` arguments. Which is *probably* a safe assumption
// in the case where this might happen, which is multiple components
// in the same app opening a connection to the same db at the same time.
final starting = startingPromises[dbName];
if (starting != null) {
return starting;
}
// If we already have a satellite process running for this db, then
// return it.
final satellite = satellites[dbName];
if (satellite != null) {
return satellite;
}
// Otherwise we need to fire it up!
final startingPromise = startProcess(
dbName: dbName,
dbDescription: dbDescription,
adapter: adapter,
migrator: migrator,
notifier: notifier,
socketFactory: socketFactory,
config: config,
).then((satellite) {
satellites[dbName] = satellite;
return satellite;
}).whenComplete(() {
startingPromises.remove(dbName);
});
startingPromises[dbName] = startingPromise;
return startingPromise;
}