GithubHelp home page GithubHelp logo

karoloortiz / delphi_async_library Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 5.0 48 KB

Async functions for delphi

License: BSD 3-Clause Clear License

Pascal 100.00%
async asynchronous delphi pascal future promise promise-library

delphi_async_library's Introduction

Delphi_Async_Library

KLib Version = 3.0

A library with some async utilities for your Delphi Apps.

Dependencies:

QUICK START

PROMISE

procedure myJob;
begin
//work
end;

procedure executionInAsyncModeWith_TPromise;
var
  _promise: TPromise;
begin
  _promise := TPromise.Create(
    procedure(resolve: TCallBack; reject: TCallBack)
    begin
      myJob;
      resolve('finish');
    end,
    procedure(value: String) // _then method
    begin
      //then method
    end,
    procedure(value: String) // _catch method
    begin
      //catch method
    end);

  // YOU CAN CHAIN THE PROMISE, USE _finally TO DESTROY THE PROMISE
  _promise._then(
    procedure(value: string)
    begin
      //then method2
    end)._then(
    procedure(value: string)
    begin
      //then method3
    end)._finally;
end;

PROMISIFY

procedure myJob;
begin
//work
end;

procedure executionInAsyncModeWith_Promisify;
var
  _callbacks: TCallBacks;
begin
  with _callbacks do
  begin
    resolve := procedure(msg: string)
      begin
        //resolve
      end;
    reject := procedure(msg: string)
      begin
	//catch
      end;
  end;
  
  promisify(myJob, _callbacks)._finally;
end;

PROMISE.ALL

procedure myJob1;
begin
//work
end;

procedure myJob2;
begin
//work
end;

procedure myJob3;
begin
//work
end;

procedure executionInAsyncModeWith_PromiseAll;
begin
  TPromise.all([myjob1, myjob2, myjob3])._then(
    procedure(value: String) // _then method
    begin
	//then
    end)._catch(
    procedure(value: String) // _catch method
    begin
    	//catch
    end)._finally;
end;

Examples:

  • example-1-async.zip: an example of use "TPromise", "promisify", "TPromise.All" "asyncifyMethod", "TAsyncMethod" and "TAsyncMethods"

If you need support, add a star to the repository and don't hesitate to contact me at [email protected]

delphi_async_library's People

Contributors

karoloortiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.