Skip to content

Commit bb4359b

Browse files
authored
Update README.MD
1 parent 5430f35 commit bb4359b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

README.MD

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async Task WaitForMouse()
182182
Built-in:
183183
* `WaitForFrames`
184184
* `WaitForSeconds`
185-
* `WaitForUnscaledSeconds`
185+
* `WaitForSecondsRealtime`
186186
* `WaitUntil`<sup>1</sup>
187187
* `WaitWhile`<sup>1</sup>
188188

@@ -197,9 +197,9 @@ Others:
197197
* `Task<>`
198198
* …anything that implements `GetAwaiter()`
199199

200-
<sup>1</sup>May cause a delegate closure.
200+
<sup>1</sup>Use the generic variants to pass a state object and avoid closures.
201201

202-
<sup>2</sup>Will spin up a Unity `Coroutine`, causing allocations.
202+
<sup>2</sup>Will spin up a Unity `Coroutine`, causing allocations. Note, `CustomYieldInstruction` implements `IEnumerator`.
203203

204204
<sup>3</sup>Very small delegate allocation.
205205

@@ -212,9 +212,9 @@ public interface IAwaitInstruction
212212
bool IsCompleted();
213213
}
214214
```
215-
It's dead simple, just place your behaviour in IsCompleted and return `true` when your criteria are met. `IsCompleted` will be evaluated every frame (depending on the `FrameScheduler`). Use a struct to avoid unnecessary allocations.
215+
It's dead simple, just place your behaviour in `IsCompleted` and return `true` when your criteria are met. `IsCompleted` will be evaluated every frame (depending on the `FrameScheduler`). Use a struct to avoid unnecessary allocations.
216216

217-
One more thing to note; you will want to implement `GetAwaiter()` so that the instruction can encapsulate itself in a `Continuation` when awaited. It is the `Continuation` which actually ends up being awaited - as a kind of decoration to make custom await instructions more straight-forward to implement (the alternative is inheritance which causes heap allocations).
217+
One more thing to note; `GetAwaiter()` is already provided through an extension method so that the instruction can encapsulate itself in an `AwaitInstructionAwaiter` when awaited. It is this struct which actually ends up being awaited - as a kind of decoration to make custom await instructions more straight-forward to implement (the alternative is inheritance which causes heap allocations).
218218

219219
```c#
220220
using UnityAsync;
@@ -227,9 +227,8 @@ public struct WaitForTimeSpan : IAwaitInstruction
227227

228228
public WaitForFrames(TimeSpan timeSpan)
229229
{
230+
// we use AsyncManager.currentTime here (and above) because it's slightly more efficient vs Time.time
230231
finishFrame = AsyncManager.currentTime + (float)timeSpan.TotalSeconds;
231-
}
232-
233-
public Continuation<WaitForTimeSpan> GetAwaiter() => new Continuation<WaitForTimeSpan>(this);
232+
}
234233
}
235234
```

0 commit comments

Comments
 (0)