Message from JavaScript discussions

May 2017

— That could even return a new promise, if cancel needs to be async

— 

An explicitly public method is preferable to using reject which may not always be public, so I tend to like the idea of having it returned like that

— Yeah, is clean enough

— Maybe just returning the function is cleaner?

— Or, the returned object could be merged into the promise object

— Including all methods / props

— Either way it would be a thunk, optimally

— Thunk?

— A thunk is a function which acts as a wrapper to another function, not quite a stored procedure but rather a stored call to another procedure

Message permanent page

— Good example is a Promise itself

— A Promise is a specific type called a continuation monad, a type of a thunk used in continuation-passing style

Message permanent page

— 

thunk is a function that encapsulates synchronous or asynchronous code inside.

thunk accepts only one callback function as an arguments, which is a CPS function.

thunk returns another thunk function after being called, for chaining operations.

thunk passes the results into a callback function after being excuted.

If the return value of callback is a thunk function, then it will be executed first and its result will be sent to another thunk for excution, or it will be sent to another new thunk function as the value of the computation.

Message permanent page