Made a tasks library(similar to js promises)

I made a library that lets you do stuff that pauses the script without doing so and get the result.

blocks:

project

what they do

the update task libary ::control block just reloads the (__task ::control) class.

the create a task ((report)) ((throw)) ::control reporter block creates a new task and the (report) and (throw) variables allow to return a value or throw an error.

the do [] later ::control reporter block lets you run some reporter and wait for it later.

the timeout for (1) seconds with value [] ::control reporter block lets you delay execution of some completion listener and send a value.

the others are straight forward

It doesnt let me run it!
image

fixed it

How do u use it?
edit: Unfortunately I don’t know very much about adts

what they do

edit: adts are custom types made using lists of text value pairs

You can drag this image to the editor that you can run:

When you run this block, the sprite says “task 1 complete” after you wait for a second. After completion of the first task and that you wait for two more seconds, the sprite says “task 2 complete”.

Demo

(After you wait for a second)

(After the completion and that you wait for two more seconds)

sorry for late reply but someday I can make my own cool project using this library

Ok?

:+1: nice idea

We can make the task result into an icon, but it needs some JavaScript:

Could it be possible with ADTs?

It could be possible with ADTs, but it requires some JavaScript to display the icon:

async function main() {
  var size = 50;
  var morph = new Morph();
  morph.bounds.setWidth(size);
  morph.bounds.setHeight(size);
  function drawTriangle(ctx) {
    ctx.beginPath();
    ctx.moveTo(size * 0, size * 0.0);
    ctx.lineTo(size * 0, size * 0.1);
    ctx.lineTo(size * 0.1, size * 0.05);
    ctx.fillStyle = "black";
    ctx.fill();
  }
  morph.render = function(ctx) {
    ctx.beginPath();
    ctx.arc(size * 0.5, size * 0.5, size * 0.45, 0, Math.PI * 2);
    ctx.fillStyle = "white";
    ctx.fill();
    ctx.beginPath();
    ctx.arc(size * 0.5, size * 0.5, size * 0.45, -0.5 * Math.PI + 0.2, 1.5 * Math.PI - 0.2);
    ctx.moveTo(size * 0.5, size * 0.1);
    ctx.lineTo(size * 0.5, size * 0.5);
    ctx.lineTo(size * 0.7, size * 0.5);
    ctx.lineWidth = 1.5;
    ctx.stroke();
    ctx.save();
    ctx.translate(size * 0.7, size * 0.45);
    drawTriangle(ctx);
    ctx.restore();
    ctx.translate(size * 0.45, size * 0.12);
    ctx.rotate(-0.5 * Math.PI);
    drawTriangle(ctx);
  }
  return morph;
}
return main();

Isn’t it possible to render things with the pen?

I know it’s hard, but it’s better than javascript. I’ll try making a trail of ({} @>) :: pen reporter block.

It’s possible because of the [paint V] on [object V] block

I want the actual Morph, not the draggable trails morph.

isn’t there an extension block that converts the costume into a morph? check the “shapes” library for an example of this

I think there are no blocks which converts the costume into a morph in the Shapes library. :sob:

Doesn’t this work?

image

It works. Thanks. But there is no option for filling the specific area.

here, use this
tasks Snap! script pic

Thanks. I will use that block and convert it.