Skip to content

Scheduling, storage and other resources

Scheduler.Once(delay, callback), Every(interval, callback), Delay(delay) and NextTick() run on your resource’s thread and are cancelled when it unloads.

Scheduler.Every(TimeSpan.FromSeconds(30), () => _ = Save());
await Scheduler.NextTick(cancellationToken);

Storage.ReadJsonAsync, WriteJsonAsync and DeleteAsync work with files in the resource’s own data folder; paths cannot leave it. Writes replace the file atomically. Needs storage.

Storage.Configuration is the manifest’s configuration object, read-only. Storage.ConfigurationAs<T>() deserialises it with camelCase property names.

CompanyConfiguration settings = Storage.ConfigurationAs<CompanyConfiguration>() ?? new();
CompanyState state = await Storage.ReadJsonAsync<CompanyState>("company.json", cancellationToken) ?? new();

Resources.Export(name, value) publishes an in-process service. Another resource can Import it only if it declares your resource as a dependency. Resources.Emit and On send local events between resources without network traffic. Exports and handlers disappear when their resource unloads.