Skip to content

Instantly share code, notes, and snippets.

@Kreijstal
Kreijstal / promises.m
Last active July 8, 2020 21:38
Promises in Mathematica
(* ::Package:: *)
(*Import like Import["https://gist.githubusercontent.com/Kreijstal/\
2a34158a1cf159b4ddc5ab3460f6efd0/raw/\
6bfc3328d9538844fabbbce9691fb3c63824ed9f/promises.m"]*)
Promise::usage="Promise[Function[{accept,reject},CustomLogic[accept[\"Success!\"],reject[\"Oh no! Error!\"]]]]"
Promise :=
Module[{local, success, failure, listen, counter = 0, Promise},
success[x_] := (local["s"] = x;(*Print[{"I've been executed",x,
local}];*)Through[local["t"][local["s"]]]; local["t"] = {};
local["resolved"] = True);