Browse Source

* Sleep function

michael 5 years ago
parent
commit
cac354d470
2 changed files with 31 additions and 1 deletions
  1. 1 1
      packages/rtl/sysutils.pas
  2. 30 0
      packages/rtl/webutils.pas

+ 1 - 1
packages/rtl/sysutils.pas

@@ -341,6 +341,7 @@ function GetEnvironmentString(Index: Integer): String;
 procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer = Nil);
 procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer = Nil);
 Procedure Abort;
 Procedure Abort;
 
 
+
 {*****************************************************************************
 {*****************************************************************************
                                Events
                                Events
 *****************************************************************************}
 *****************************************************************************}
@@ -7894,6 +7895,5 @@ begin
   Result:=BoolToStr(Self,UseBoolStrs=TUseBoolStrs.True);
   Result:=BoolToStr(Self,UseBoolStrs=TUseBoolStrs.True);
 end;
 end;
 
 
-
 end.
 end.
 
 

+ 30 - 0
packages/rtl/webutils.pas

@@ -0,0 +1,30 @@
+unit webutils;
+
+{$mode objfpc}
+
+interface
+
+uses
+  web, js;
+
+function Sleep(ms: NativeInt): TJSPromise;
+
+implementation
+
+function Sleep(ms: NativeInt): TJSPromise;
+
+begin
+  Result := TJSPromise.New(
+  procedure(resolve,reject : TJSPromiseResolver)
+  begin
+    window.setTimeout(
+    procedure()
+    begin
+      resolve(ms);
+    end,
+    ms);
+  end);
+end;
+
+end.
+