; WaitJob Example ; --------------- ; Requires Extended mode. Graphics 640,480,0,2 SetBuffer BackBuffer() ; The worker hashes the save file data over and over to fingerprint it Worker Function HashSave(inputBank) passes=PeekInt(inputBank,0) digest$="HERO=Aria LEVEL=7 GOLD=852 CHECKPOINT=SkyTemple" For pass=1 To passes digest=Sha256Text(digest) Next ; Return the final 32-byte digest as the result Bank Return Sha256TextBytes(digest) End Function inputBank=CreateBank(4) PokeInt inputBank,0,300000 job=StartJob(HashSave,inputBank,1L) FreeBank inputBank ; Show one frame before blocking so the window is visible while we wait Cls Text 70,220,"Hashing save file on a worker thread - please wait..." Flip ; WaitJob blocks until the Job is terminal, or 10 seconds pass start=MilliSecs() If Not WaitJob(job,10000) Then RuntimeError "Save hash timed out" elapsed=MilliSecs()-start If JobState(job)<>JOB_SUCCEEDED Then RuntimeError JobError(job) resultBank=TakeJobResult(job) fingerprint$=Hex(PeekInt(resultBank,0))+Hex(PeekInt(resultBank,4))+Hex(PeekInt(resultBank,8)) FreeBank resultBank FreeJob job While Not KeyDown(1) Cls Text 0,0,"Esc: exit" Text 70,190,"WaitJob(job,10000) returned true after "+elapsed+" ms" Text 70,220,"Save fingerprint: "+fingerprint Text 70,250,"WaitJob does not render or pump events - use PollJob in a game loop" Flip Wend End