Skip to content

Commit

Permalink
Bump the dotnet group in /docs/orleans/grains/snippets/timers with 3 …
Browse files Browse the repository at this point in the history
…updates (#41810)

* Bump the dotnet group

Bumps the dotnet group in /docs/orleans/grains/snippets/timers with 3 updates: [Microsoft.Orleans.Core.Abstractions](https://github.com/dotnet/orleans), [Microsoft.Orleans.Reminders](https://github.com/dotnet/orleans) and [Microsoft.Orleans.Sdk](https://github.com/dotnet/orleans).


Updates `Microsoft.Orleans.Core.Abstractions` from 8.1.0 to 8.2.0
- [Release notes](https://github.com/dotnet/orleans/releases)
- [Commits](dotnet/orleans@v8.1.0...v8.2.0)

Updates `Microsoft.Orleans.Reminders` from 8.1.0 to 8.2.0
- [Release notes](https://github.com/dotnet/orleans/releases)
- [Commits](dotnet/orleans@v8.1.0...v8.2.0)

Updates `Microsoft.Orleans.Core.Abstractions` from 8.1.0 to 8.2.0
- [Release notes](https://github.com/dotnet/orleans/releases)
- [Commits](dotnet/orleans@v8.1.0...v8.2.0)

Updates `Microsoft.Orleans.Sdk` from 8.1.0 to 8.2.0
- [Release notes](https://github.com/dotnet/orleans/releases)
- [Commits](dotnet/orleans@v8.1.0...v8.2.0)

---
updated-dependencies:
- dependency-name: Microsoft.Orleans.Core.Abstractions
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dotnet
- dependency-name: Microsoft.Orleans.Reminders
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dotnet
- dependency-name: Microsoft.Orleans.Core.Abstractions
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dotnet
- dependency-name: Microsoft.Orleans.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dotnet
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update docs/orleans/grains/snippets/timers/Timers.csproj

* Fix issue with API breaking changes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Pine <david.pine@microsoft.com>
Co-authored-by: David Pine <david.pine.7@gmail.com>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent e0729e2 commit 3f7b125
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
14 changes: 8 additions & 6 deletions docs/orleans/grains/snippets/timers/PingGrain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Orleans.Runtime;
using Orleans.Timers;
using Orleans.Timers;

namespace Timers;

Expand All @@ -19,18 +18,21 @@ public PingGrain(
IGrainContext grainContext)
{
// Register timer
timerRegistry.RegisterTimer(
timerRegistry.RegisterGrainTimer(
grainContext,
asyncCallback: static async state =>
callback: static async (state, cancellationToken) =>
{
// Omitted for brevity...
// Use state
await Task.CompletedTask;
},
state: this,
dueTime: TimeSpan.FromSeconds(3),
period: TimeSpan.FromSeconds(10));
options: new GrainTimerCreationOptions
{
DueTime = TimeSpan.FromSeconds(3),
Period = TimeSpan.FromSeconds(10)
});

_reminderRegistry = reminderRegistry;

Expand Down
6 changes: 3 additions & 3 deletions docs/orleans/grains/snippets/timers/Timers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="8.1.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.1.0" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="8.1.0" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="8.2.0" />
</ItemGroup>

</Project>
17 changes: 8 additions & 9 deletions docs/orleans/grains/timers-and-reminders.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Timers and reminders
description: Learn how to use timers and reminders in .NET Orleans.
ms.date: 07/03/2024
ms.date: 08/01/2024
---

# Timers and reminders
Expand All @@ -16,14 +16,13 @@ Each activation may have zero or more timers associated with it. The runtime exe

## Timer usage

To start a timer, use the <xref:Orleans.Grain.RegisterTimer%2A?displayProperty=nameWithType> method, which returns an <xref:System.IDisposable> reference:
To start a timer, use the `RegisterGrainTimer` method, which returns an <xref:System.IDisposable> reference:

```csharp
protected IDisposable RegisterTimer(
Func<object, Task> asyncCallback, // function invoked when the timer ticks
object state, // object to pass to asyncCallback
TimeSpan dueTime, // time to wait before the first timer tick
TimeSpan period) // the period of the timer
protected IDisposable RegisterGrainTimer(
Func<object, Task> callback, // function invoked when the timer ticks
object state, // object to pass to callback
GrainTimerCreationOptions options) // timer creation options
```

To cancel the timer, you dispose of it.
Expand All @@ -33,8 +32,8 @@ A timer ceases to trigger if the grain is deactivated or when a fault occurs and
***Important considerations:***

* When activation collection is enabled, the execution of a timer callback doesn't change the activation's state from idle to in-use. This means that a timer can't be used to postpone the deactivation of otherwise idle activations.
* The period passed to `Grain.RegisterTimer` is the amount of time that passes from the moment the Task returned by `asyncCallback` is resolved to the moment that the next invocation of `asyncCallback` should occur. This not only makes it impossible for successive calls to `asyncCallback` to overlap, but also makes it so that the length of time `asyncCallback` takes to complete affects the frequency at which `asyncCallback` is invoked. This is an important deviation from the semantics of <xref:System.Threading.Timer?displayProperty=fullName>.
* Each invocation of `asyncCallback` is delivered to an activation on a separate turn, and never runs concurrently with other turns on the same activation. However, `asyncCallback` invocations aren't delivered as messages and thus aren't subject to message interleaving semantics. This means that invocations of `asyncCallback` behave as if the grain is re-entrant and executes concurrently with other grain requests. In order to use the grain's request scheduling semantics, you can call a grain method to perform the work you would have done within `asyncCallback`. Another alternative is to use an `AsyncLock` or a <xref:System.Threading.SemaphoreSlim>. A more detailed explanation is available in [Orleans GitHub issue #2574](https://github.com/dotnet/orleans/issues/2574).
* The period passed to `Grain.RegisterGrainTimer` is the amount of time that passes from the moment the `Task` returned by `callback` is resolved to the moment that the next invocation of `callback` should occur. This not only makes it impossible for successive calls to `callback` to overlap, but also makes it so that the length of time `callback` takes to complete affects the frequency at which `callback` is invoked. This is an important deviation from the semantics of <xref:System.Threading.Timer?displayProperty=fullName>.
* Each invocation of `callback` is delivered to an activation on a separate turn, and never runs concurrently with other turns on the same activation. However, `callback` invocations aren't delivered as messages and thus aren't subject to message interleaving semantics. This means that invocations of `callback` behave as if the grain is re-entrant and executes concurrently with other grain requests. In order to use the grain's request scheduling semantics, you can call a grain method to perform the work you would have done within `callback`. Another alternative is to use an `AsyncLock` or a <xref:System.Threading.SemaphoreSlim>. A more detailed explanation is available in [Orleans GitHub issue #2574](https://github.com/dotnet/orleans/issues/2574).

## Reminders

Expand Down

0 comments on commit 3f7b125

Please sign in to comment.