orthecreedence / blackbird

Common Lisp promise implementation (successor to cl-async-future)
83 stars 10 forks source link

Added *promise-keep-specials* #1

Closed ivan4th closed 9 years ago

ivan4th commented 9 years ago

Sometimes it's desirable to keep some kind of context available via special vars during execution of a promise chain. For instance one may want to keep http request related context while serving a request in a web app. I added promise-keep-specials special var that can be used for such purposes:

(pushnew '*my-var* bb:*promise-keep-specials*)

Several notes:

  1. Due to extra wrapping of callbacks/errbacks, this slightly changes the semantics of attach-errback - namely, it no longer can detect whether the callback was already added. Don't know whether that's critical. For purposes of promise forwarding, the non-wrapping version named do-attach-errback is used.
  2. I thought about making alet/alet* bindings of special vars work in such way that these vars are auto-registered in promise-keep-specials while executing any code related to that alet/alet* form, but couldn't quite wrap my head around it (how to do it properly and whether this is right thing at all)
  3. (As a side note) there was an unused gensym var in alet macro, fixed it too.
orthecreedence commented 9 years ago

Nice work! I learned about progv reading through the changes, had never heard of it before.

it no longer can detect whether the callback was already added

I don't think this is an issue at all. In fact I just removed the duplicate checking callback/errback code/docs because I don't see the purpose of checking if it was already added (and maybe there are cases where you'd want to fire the same callback twicr).

I thought about making alet/alet* bindings of special vars work in such way that these vars are auto-registered in promise-keep-specials while executing any code related to that alet/alet* form

Interesting, would it auto-detect var names wrapped in * or would it add all the bound variables to the *promise-keep-specials* collection? Or maybe I'm misunderstanding what you were thinking here.

Thanks for the update!

ivan4th commented 9 years ago

Concerning progv - actually it was @archimag who told me about it after I showed him the preliminary version of special var keeping code, although I knew about it in the past I managed to forget it. He's currently integrating his RESTAS web framework with wookie. progv can also be used to make REPL integration code somewhat prettier (BTW: today I've noticed that SLIME broke eval hooks back in September, wrote a pull request to fix it which is already accepted).

As of let - yes, perhaps *-wrapping needs to be looked at there to detect special vars. I thought that this is rather dirty hack and thus decided not to do it for now.