Skip to content

Commit 6850899

Browse files
authored
Update task.yaml
1 parent c3983f6 commit 6850899

File tree

1 file changed

+63
-67
lines changed
  • content/en-us/reference/engine/libraries

1 file changed

+63
-67
lines changed

content/en-us/reference/engine/libraries/task.yaml

Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: task
22
type: library
33
summary: |
4-
Allows for functions and threads to be coordinated with the Task Scheduler.
4+
Allows for functions and threads to be coordinated with the engine's scheduler.
55
description: |
66
The **task** library allows for functions and threads to be scheduled with the
7-
Task Scheduler.
7+
engine's scheduler.
88
99
The functions available in this library generally support functions and
1010
threads. In most cases using a function is sufficient, but for more advanced
@@ -15,29 +15,30 @@ properties:
1515
functions:
1616
- name: task.spawn
1717
summary: |
18-
Calls/resumes a function/coroutine immediately through the engine
18+
Calls/resumes a function/coroutine immediately through the engine's
1919
scheduler.
2020
description: |
21-
Accepts a function or a thread (as returned by coroutine.create) and
22-
calls/resumes it immediately through the engine's scheduler. Arguments
23-
after the first are sent to the function/thread.
21+
Accepts a function or a thread (as returned by
22+
`Library.coroutine.create()`) and calls/resumes it immediately through the
23+
engine's scheduler. Arguments after the first are sent to the
24+
function/thread.
2425
25-
This function is based on the fastSpawn pattern rather than being a
26-
replacement for the deprecated global `spawn` function. It is recommended
27-
that this function be used in place of fastSpawn.
26+
This function is based on the `fastSpawn` pattern rather than being a
27+
replacement for the deprecated global `spawn()` function. It is
28+
recommended that this function be used in place of `fastSpawn`.
2829
2930
If the calling script is currently running in a serial execution phase,
3031
then the spawned function or thread is resumed in the current serial
3132
execution phase. If the calling script is currently running in a parallel
3233
execution phase, then the spawned function or thread is resumed in the
33-
current parallel execution phase. For more information, see
34-
[Parallel Luau](../../../scripting/multithreading.md).
34+
current parallel execution phase. For more information, see [Parallel
35+
Luau](../../../scripting/multithreading.md).
3536
parameters:
3637
- name: functionOrThread
3738
type: function | thread
3839
default:
3940
summary: |
40-
A function or a thread returned by coroutine.create.
41+
A function or a thread returned by `Library.coroutine.create()`.
4142
- name: ...
4243
type: Variant
4344
default:
@@ -54,12 +55,9 @@ functions:
5455
Calls/resumes a function/coroutine at the end of the current resumption
5556
cycle.
5657
description: |
57-
Accepts a function or a thread (as returned by coroutine.create) and
58-
defers it until the end of the current resumption cycle, which is a point
59-
later in the current frame, but never during the next frame. Once it reaches
60-
the end of the current resumption cycle, the function or thread is resumed
61-
with the engine's scheduler like with `Library.task.spawn()`.
62-
Arguments after the first are sent to the function/thread.
58+
Accepts a function or a thread (as returned by
59+
`Library.coroutine.create()`) and defers it until the end of the current
60+
resume point within the current frame.
6361
6462
This function should be used when a similar behavior to
6563
`Library.task.spawn()` is desirable, but the thread does not need to run
@@ -69,8 +67,8 @@ functions:
6967
then the deferred function or thread is resumed in a serial execution
7068
phase. If the calling script is currently running in a parallel execution
7169
phase, then the deferred function or thread is resumed in a parallel
72-
execution phase. For more information, see
73-
[Parallel Luau](../../../scripting/multithreading.md).
70+
execution phase. For more information, see [Parallel
71+
Luau](../../../scripting/multithreading.md).
7472
parameters:
7573
- name: functionOrThread
7674
type: function | thread
@@ -93,17 +91,18 @@ functions:
9391
Schedules a function/coroutine to be called/resumed on the next Heartbeat
9492
after the given duration (in seconds) has passed, without throttling.
9593
description: |
96-
Accepts a function or a thread (as returned by coroutine.create) and
97-
schedules it to be called/resumed on the next
98-
`Class.RunService.Heartbeat|Heartbeat` after the given amount of time in
99-
seconds has elapsed. Arguments after the second are sent to the
94+
Accepts a function or a thread (as returned by
95+
`Library.coroutine.create()`) and schedules it to be called/resumed on the
96+
next `Class.RunService.Heartbeat|Heartbeat` after the given amount of time
97+
in seconds has elapsed. Arguments after the second are sent to the
10098
function/thread.
10199
102-
This function differs from the deprecated global `delay` function in that
103-
**no throttling occurs**: on the very same Heartbeat step in which enough
104-
time has passed, the function is guaranteed to be called/resumed.
105-
Providing a duration of zero (0) will guarantee that the function is
106-
called on the very next Heartbeat.
100+
This function differs from the deprecated global `delay()` function in
101+
that **no throttling occurs**: on the very same
102+
`Class.RunService.Heartbeat|Heartbeat` step in which enough time has
103+
passed, the function is guaranteed to be called/resumed. Providing a
104+
duration of zero (`0`) will guarantee that the function is called on the
105+
very next `Class.RunService.Heartbeat|Heartbeat`.
107106
108107
You can calculate the actual time passed by calling `Library.os.clock()`
109108
upon scheduling and in the scheduled function.
@@ -112,8 +111,8 @@ functions:
112111
then the delayed function or thread is resumed in a serial execution
113112
phase. If the calling script is currently running in a parallel execution
114113
phase, then the delayed function or thread is resumed in a parallel
115-
execution phase. For more information, see
116-
[Parallel Luau](../../../scripting/multithreading.md).
114+
execution phase. For more information, see [Parallel
115+
Luau](../../../scripting/multithreading.md).
117116
parameters:
118117
- name: duration
119118
type: number
@@ -142,19 +141,19 @@ functions:
142141
Causes the following code to be run in parallel.
143142
description: |
144143
If the calling script is currently running in a serial execution phase,
145-
`desynchronize` suspends the script and the script will be resumed in the
146-
next parallel execution phase. If the calling script is currently running
147-
in a parallel execution phase, `desynchronize` returns immediately and has
148-
no effect.
144+
`desynchronize()` suspends the script and the script will be resumed in
145+
the next parallel execution phase. If the calling script is currently
146+
running in a parallel execution phase, `desynchronize()` returns
147+
immediately and has no effect.
149148
150-
Only scripts which are descendants of an Actor may call this method. If a
151-
script outside of an Actor calls this method, an error will be raised.
152-
ModuleScript's may also call `desynchronize` as long as the instantiation
153-
of the module calling it was required by a script that is a descendant of
154-
an Actor.
149+
Only scripts which are descendants of an `Class.Actor` may call this
150+
method. If a script outside of an `Class.Actor` calls this method, an
151+
error will be raised. `Class.ModuleScript|ModuleScripts` may also call
152+
`desynchronize()` as long as the instantiation of the module calling it
153+
was required by a script that is a descendant of an `Class.Actor`.
155154
156-
For more information, see
157-
[Parallel Luau](../../../scripting/multithreading.md).
155+
For more information, see [Parallel
156+
Luau](../../../scripting/multithreading.md).
158157
parameters:
159158
returns:
160159
- type: ()
@@ -166,19 +165,19 @@ functions:
166165
Causes the following code to be run in serial.
167166
description: |
168167
If the calling script is currently running in a parallel execution phase,
169-
`synchronize` suspends the script and the script will be resumed in the
168+
`synchronize()` suspends the script and the script will be resumed in the
170169
next serial execution phase. If the calling script is currently running in
171-
a serial execution phase, `synchronize` returns immediately and has no
170+
a serial execution phase, `synchronize()` returns immediately and has no
172171
effect.
173172
174-
Only scripts which are descendants of an Actor may call this method. If a
175-
script outside of an Actor calls this method, an error will be raised.
176-
ModuleScript's may also call `synchronize` as long as the instantiation of
177-
the module calling it was required by a script that is a descendant of an
178-
Actor.
173+
Only scripts which are descendants of an `Class.Actor` may call this
174+
method. If a script outside of an `Class.Actor` calls this method, an
175+
error will be raised. `Class.ModuleScript|ModuleScripts` may also call
176+
`synchronize()` as long as the instantiation of the module calling it was
177+
required by a script that is a descendant of an `Class.Actor`.
179178
180-
For more information, see
181-
[Parallel Luau](../../../scripting/multithreading.md).
179+
For more information, see [Parallel
180+
Luau](../../../scripting/multithreading.md).
182181
parameters:
183182
returns:
184183
- type: ()
@@ -187,19 +186,18 @@ functions:
187186
code_samples:
188187
- name: task.wait
189188
summary: |
190-
Yields the current thread until the next Heartbeat in which the given
191-
duration (in seconds) has passed, without throttling.
189+
Yields the current thread without throttling.
192190
description: |
193191
Yields the current thread until the given duration (in seconds) has
194192
elapsed, then resumes the thread on the next
195193
`Class.RunService.Heartbeat|Heartbeat` step. The actual amount of time
196194
elapsed is returned.
197195
198-
If no duration is given, it will default to zero (0). This means the
196+
If no duration is given, it will default to zero (`0`). This means the
199197
thread resumes on the very next step, which is equivalent in behavior to
200-
`RunService.Heartbeat:Wait()`
198+
`Class.RunService.Heartbeat:Wait()`
201199
202-
Unlike the deprecated global `wait`, this function **does not throttle**
200+
Unlike the deprecated global `wait()`, this function **does not throttle**
203201
and guarantees the resumption of the thread on the first Heartbeat that
204202
occurs when it is due. This function also only returns the elapsed time
205203
and nothing else.
@@ -226,9 +224,9 @@ functions:
226224
Cancels a thread, preventing it from being resumed.
227225
description: |
228226
Cancels a thread and closes it, preventing it from being resumed manually
229-
or by the task scheduler.
227+
or by the engine's scheduler.
230228
231-
This function can be used with other members of the task library that
229+
This function can be used with other members of the **task** library that
232230
return a thread to cancel them before they are resumed. For example:
233231
234232
```lua
@@ -239,15 +237,13 @@ functions:
239237
task.cancel(thread)
240238
```
241239
242-
Note: Threads may be in a state where it is impossible to cancel them. For
243-
example, the currently executing thread and threads that have resumed
244-
another coroutine may not be cancelled. If this is the case, a lua error
245-
will be generated.
246-
247-
However, code should not rely on specific thread states or conditions
248-
causing `Library.task.cancel()` to fail. It is possible that future
249-
updates will eliminate these constraints and allow threads in these states
250-
to be successfully cancelled.
240+
Note that threads may be in a state where it is impossible to cancel them.
241+
For example, the currently executing thread and threads that have resumed
242+
another coroutine may not be cancelled. If this is the case, an error will
243+
be generated. However, code should not rely on specific thread states or
244+
conditions causing `Library.task.cancel()` to fail. It is possible that
245+
future updates will eliminate these constraints and allow threads in these
246+
states to be successfully cancelled.
251247
parameters:
252248
- name: thread
253249
type: thread

0 commit comments

Comments
 (0)