Giter VIP home page Giter VIP logo

aplasync's Introduction

Asynchronous task in APL

This simple implementation of Asynchronous in APL. The implementation is based on Dyalog APL thread functions as:

  & ⎕TPUT ⎕TGET

That means that task are running in same process in several APL thread.

Usage

To load library run in the session:

  ⎕CY './Distribution/aplasync.dws'

Functions

asyncTask function

asyncTask function creates task. It will return the task namespace with unique token and namespace where task is run.

Input is name and arguments of function which should be urn in the task (APL thread).

asyncTask will initiate execution of function in new APL thread.

The result should be awaited with awaitTask function.

awaitTask function

awaitTask awaits execution of the task created by asyncTask. It will wait that function is completed with execution.

Input is task defined in asyncTask.

Output is result of function used in asyncTask.

A task can be only once awaited.

Example

Step 1. Let have a APL function which should be executed as asynchronous task:

   resfooFn arg;val1;val2
   Do something:
  ⎕DL arg
   Return something: 
  val1arg
  val2⎕NS''
  val2.val1arg
  resval1 val2
  

Step 2. Lets make 3 tasks:

  task1asyncTask 'fooFn' 2
  task2asyncTask 'fooFn' 5
  task3asyncTask 'fooFn' 1

Step 3. Clean result if exist:

   ⎕EX 'res1' 'res2' 'res3'

Step 4.a. And await them:

  res1awaitTask task1
  res2awaitTask task2
  res3awaitTask task3

Step 5. Test result:

  val1 val2res1
  2val1
  2val2.val1

  val1 val2res2
  5val1
  5val2.val1

  val1 val2res3
  1val1
  1val2.val1

Step 4.b. or to await with measure time (remember to make make tasks from Step 2.):

  ai⎕AI[2 3]  res1awaitTask task1  ai-⎕AI[2 3]  'res1' res1 ((2res1).val1)
  ai⎕AI[2 3]  res2awaitTask task2  ai-⎕AI[2 3]  'res2' res2 ((2res2).val1)
  ai⎕AI[2 3]  res3awaitTask task3  ai-⎕AI[2 3]  'res3' res3 ((2res3).val1)

Note: Interesting is that task2 task take on c.a. 3 seconds, it was running in same time task1 task. In order to see such result the step 2. 3. 4.a (or 4.b) should be executed together, in sequence.

Example of results of 4.b.

  ai⎕AI[2 3]  res1awaitTask task1  ai-⎕AI[2 3]  'res1' res1 ((2res1).val1)
0 ¯1977
 res1  2  #.[Namespace]   2
  ai⎕AI[2 3]  res2awaitTask task2  ai-⎕AI[2 3]  'res2' res2 ((2res2).val1)
0 ¯2995
 res2  5  #.[Namespace]   5
  ai⎕AI[2 3]  res3awaitTask task3  ai-⎕AI[2 3]  'res3' res3 ((2res3).val1)
0 0
 res3  1  #.[Namespace]   1

Scalar example

   resfooFn1 arg
   Do something:
  ⎕DL arg
  res7
  
  task4asyncTask 'fooFn1' 2

And await them:

  res4awaitTask task4

and test

  7res4

aplasync's People

Contributors

mvranic avatar

Watchers

James Cloos 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.