apnadkarni/tcl-promise

Return dictionary for on_fulfill and on_reject

Opened this issue · 0 comments

16:25] schelte Now I need to figure out how to combine that with my www package for fetching urls.
[16:41] «apn» Iirc, that is based on coroutines is it not?
[16:41] schelte Yes.
[16:42] schelte I'm playing with after $ms [list [info coroutine]] to get a feel for using promises together with coroutines.
[16:44] «apn» Yeah, I'm unsure about using the two in combination (the promise package is event loop based). Don't recall trying it out.
[16:44] «apn» You can see the pgeturl implementation here - https://tcl-promise.magicsplat.com/promise-1.1.0.html#::promise::pgeturl (click on the Show source link)
[16:45] «apn» I'd be interested in what a coroutine equivalent would look like
[16:45] schelte The http package is way too cumbersome to work with, in my opinion.
[16:45] schelte I'll let you know once I figure it out.
[16:45] «apn» I think @pooryorick's ycl coroutine bundle also has something in this space but could be wrong
[16:47] schelte I'm optimistic that it shouldn't be too complicated.

[17:49] schelte It's actually super simple: async pwww args {www {*}$args}

[18:01] apn Nice. Is that the promise::async? If not, would be interested in the code.

[18:04] schelte A remark on the manual page for the "then" method: It says "Both reactions are called with an additional argument which is the value with which the promise was settled." It doesn't mention that the on_reject reaction gets a second argument.
[18:06] schelte The www package also provides information via the return options on success. It doesn't seem like there's a way to get at that in the on_fulfill reaction.
[18:13] schelte But that's easily resolved: async pwwwex args {try {www {*}$args} on ok {result edict} {return [list $result $edict]}}
[18:21] schelte The second argument is the edict value.