nielsAD / lape

Scripting engine with Pascal-like syntax for FPC and Delphi
118 stars 28 forks source link

Anonymous functions. #99

Open ghost opened 7 years ago

ghost commented 7 years ago

Allows elegant implementation of event driven code and other similar idioms. Node.js makes heavy use of such concepts; a more relevant example would be OmniThreadLibrary (Delphi-only):

procedure TfrmDemoParallelAsync.btnAsyncClick(Sender: TObject);
begin
  btnAsync.Enabled := false;

  Parallel.Async(
    procedure
    begin
      // executed in background thread
      Sleep(500);
      MessageBeep($FFFFFFFF);
    end,

    procedure
    begin
      // executed in main thread
      btnAsync.Enabled := true;
    end
  );
end;