From ef09a568e034735995d0f6af747821582bc9dfd0 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 7 Oct 2021 13:58:38 +0200 Subject: [PATCH] Initial README Added the initial documentation, more will be added later (perhaps in a wiki) --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..791873a --- /dev/null +++ b/README.md @@ -0,0 +1,80 @@ +

+ +

+

Threaded task chaining for JavaScript

+
+

Monkeydo uses the portable data format JSON to read tasks, making it easy to read by primates and machines alike.

+ + + +
+
+{
+  "tasks": [
+    [0,"myJavaSriptMethod","someArgument","anotherArgument"]
+  ]
+}
+
+
+ + + + + + + + + + + + + + + + + +
Array keyDescription
0Delay
Wait this many milliseconds before running this task
1Method
Name of the JavaScript method to call
2+nArguments
Some amount of arguments to pass to the method
+
+

Use Monkeydo

+

Monkeydo comes as an importable ECMAScript 6 module. In this guide we'll import this directly from a ./modules/ folder, but any web-accesible location will work.

+
    +
  1. Import Monkeydo from your repo clone or download +
    +import { default } from "./modules/Monkeydo/Monkeydo.mjs";
    +
    +
  2. +
  3. Define your JS methods +
    +const methods = {
    +  myJavaScriptMethod: (foo,bar) => {
    +    console.log(foo,bar);
    +  }
    +}
    +
    +
  4. +
  5. Define your tasks in a JSON file (or directly in JavaScript) +
    +{
    +  "tasks": [
    +    [0,"myJavaSriptMethod","I see skies of","blue"],
    +    [300,"myJavaSriptMethod","red","roses too"],
    +    [160,"myJavaSriptMethod","I see them","bloom"],
    +    [1200,"myJavaSriptMethod","for","me and you"]
    +  ]
    +}
    +
    +
  6. +
  7. Initialize and run Monkeydo with your methods and manifest +
    +const monkey = new Monkeydo(methods,manifest);
    +monkey.do();
    +
    +
  8. +
+

The example above would be the same as running:

+
+console.log("I see skies","of blue"); // Right away
+console.log("red","roses too"); // 300 milliseconds after the first
+console.log("I see them","bloom"); // 160 milliseconds after that one
+console.log("for","me and you"); // and lastly, 1200 after that
+