deliciousrobots/green-threads — pull request #1 by orthecreedence (2013-03-25 21:29:34+00:00)
Title: Update to use cl-async-future (now a standalone library) for green-threads future implementation.

Hey! I was thinking about this project lately and wanted to make some updates to integrate the futures work I've done on [cl-async-future](https://github.com/orthecreedence/cl-async-future) with what you've done, the end result being the ability to add green-threads to any cl-async (or cl-async-future) enabled application. I recently made cl-async-future standalone (it's pure-lisp, zero dependencies) so it can be used in projects other than ones that use cl-async.

A benefit to using the cl-async-future library is that you get nested future operations for free. Consider this:

```common-lisp
(defpackage :green-future-test
(:use :cl :green-threads :cl-async-future))
(in-package :green-future-test)

(defun fdelay (val)
"Simple delay function, finish a future with the given value."
(let ((future (make-future)))
(cl-async:delay (lambda () (finish future val)) :time 1)
future))

(cl-async:start-event-loop
(lambda ()
(with-green-thread
;; nest some async operations, then return a final result
(let ((f (alet ((x (fdelay 4)))
(alet ((y (fdelay (+ x 5))))
;; return the final value, making it available to top-level future `f`
(+ y 3)))))
(format t "Start waiting.~%")
;; 2s delay, then prints "Final value: 12"
(format t "Final value: ~a~%" (wait-on f))))))
```

Because of this, there are a few API changes, mainly where there are collisions between green-threads and cl-async-future:

* RENAME: complete-future => finish
* RENAME: future-complete-p => future-finished-p

I updated the tests with these API changes (everything passes) and also did a few hand tests with more complicated examples (like multiple threads waiting on the same future) and everything seems to work great. Also, I made sure that any symbols green-threads uses from cl-async-future are exported from green-threads, so that apps only need to `:use` green-threads, not both libraries.

Anyway, hopefully this works for green-threads. Feel free to let me know if you have any questions/updates.