currently trying to make first steps to create my own Miletus component for controlling the Raspberry GPIO interface. I derived it from TComponent and I thought its a good idea to use a timer for polling the GPIO. Inside the timer event I'm using the GPIORead(AGPIOPin: Integer): TJSPromise; defined in WEBLib.MiletusRaspi.pas. I marked the timer event procedure with [async] and it compiled fine. When using my control in a Miletus test app, the compiler is complaining that using Await is only allowed in async procedures. What is my mistake here?
Best regards
TMiletusRaspberryGPIO = class(TComponent)
private
FPollingTimer : TTimer;
[async]procedure OnTimer(Sender : TObject);
public
constructor Create(AOwner: TComponent); override;
end;
constructor TMiletusRaspberryGPIO.Create(AOwner: TComponent);
begin
inherited;
FPollingTimer:= TTimer.Create(nil);
FPollingTimer.OnTimer:= OnTimer;
end;
[async]
procedure TMiletusRaspberryGPIO.OnTimer(Sender : TObject);
var
value : Integer;
begin
value:= Await(Integer, GPIORead(item.Port));
end;
I got stuck on this as well, You can also mark the procedure async by using a directive. For some reason the compiler likely does not see the attribute:
Fails
[async]
function HashForString(AString: string): string; //async;
Works
//[async]
function HashForString(AString: string): string; async;
Do you have more details? Do you add the [async] attribute on a class method?
Also, note that the pas2js compiler specifies to use the async decorator. In TMS WEB Core, we added the extra capability to use an attribute on the class method. The reason for this is that the attribute is a standard Pascal language feature the Delphi LSP recognizes while the async decorator extension from the pas2js compiler not.