Página 1 de 1

Asynchronous functions on next Xailer release

Publicado: Dom Sep 01, 2019 1:42 pm
por ignacio


Sample of use:
1 ) With commands

Código: Seleccionar todo

METHOD ASYNC Btn1Click( oSender ) CLASS TForm1
...
   AWAIT INLINE {||
         FOR nFor := 1 TO 100
            Sleep(10)
            SYNCHRO INLINE {|| ::oPb1:nValue := nFor }
         NEXT
      RETURN "Exit from first serie"
      }

   // lastAwait is a private VAR with the return value of previous Await command

   AWAIT INLINE {||
      SYNCHRO INLINE { ||  Msginfo( lastWait ) }

      RETURN NIL
      }
RETURN NIL
2) OOP version:

Código: Seleccionar todo

   LOCAL oFuture AS CLASS TFuture
   LOCAL oTask AS CLASS TFutureTask
   LOCAL bWork
   LOCAL nFor

   oFuture := TFuture():New()

   bWork := { ||
      FOR nFor := 1 TO 100
         Sleep(30)
         oFuture:AddSynchroTask( {||::oPb3:nValue := nFor } )
      NEXT
      RETURN "Exit from third serie"
   }

   oFuture:OnComplete := {|| Msginfo( oTask:ReturnValue )  }
   oTask := oFuture:AddThreadTask( bWork )

 RETURN Nil