JobFinished ( job )
Parameters
| job - a Job handle returned by StartJob |
Description
|
Returns True once a job has reached a terminal state. Terminal means succeeded, failed, or cancelled - JobFinished does not tell you which, so follow up with JobState before celebrating. It answers the simple per-job question "is my pathfinding done yet?" inside a frame, without any side effects: unlike PollJob and WaitAnyJob it consumes nothing, so you can ask every frame and the answer stays consistent. Use it when you are tracking one specific job in a variable; use PollJob when you want to be handed whichever job finished next. Both patterns end the same way: JobState to route, TakeJobResult on success, FreeJob always. For the full story, see the Using Background Jobs guide. Requires Extended mode. See also: JobState, PollJob, WaitJob, TakeJobResult, JobProgress. |
Example
; JobFinished Example ; ------------------- ; Requires Extended mode. Graphics 640,480,0,2 SetBuffer BackBuffer() ; The worker carves a dungeon level on a background thread Worker Function CarveDungeon(inputBank) rooms=PeekInt(inputBank,0) For room=1 To rooms ; Busy digging loop standing in for real level generation For dig=1 To 700000 noise#=Sin(dig)*Sqr(dig) Next SetJobProgress room,rooms,"Carving room "+room Next Return CreateBank() End Function inputBank=CreateBank(4) PokeInt inputBank,0,30 job=StartJob(CarveDungeon,inputBank,1L) FreeBank inputBank frame=0 While Not KeyDown(1) Cls frame=frame+1 ; JobFinished is true for succeeded, failed, or cancelled Jobs finished=JobFinished(job) ; The main loop keeps animating while the worker digs Color 200,180,90 Rect 300+Sin(frame*4)*180,300,40,40,True ; Draw the loading bar progress=JobProgress(job) Color 60,60,80 Rect 70,220,500,24,True Color 90,200,120 Rect 70,220,progress*500/1000,24,True Color 255,255,255 Rect 70,220,500,24,False Text 0,0,"Esc: exit" Text 70,190,"The game keeps running while the dungeon generates" Text 70,254,"JobFinished(job) = "+finished If finished Then Text 70,274,"Finished - the completion notification is still unconsumed" Flip Wend FreeJob job End
Index