gscript r8 - trunk
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: gscript r8 - trunk
- Date: Tue, 16 Sep 2008 11:42:30 +0000 (UTC)
Author: alexl
Date: Tue Sep 16 11:42:30 2008
New Revision: 8
URL: http://svn.gnome.org/viewvc/gscript?rev=8&view=rev
Log:
2008-09-16 Alexander Larsson <alexl redhat com>
* gtk.js:
Unify currying.
Clean up names
Modified:
trunk/ChangeLog
trunk/gtk.js
Modified: trunk/gtk.js
==============================================================================
--- trunk/gtk.js (original)
+++ trunk/gtk.js Tue Sep 16 11:42:30 2008
@@ -21,22 +21,30 @@
/* Wrap the GIO-style async op for the yield format */
-function open_yield (filename, flags) {
- let f = filename;
- let fl = flags;
- let curried = function(cb) {
- open_async (f, fl, cb);
- }
- curried.finish = function(res) {
- return open_finish (f, res);
- }
- /* Basically we return a curried version of open_async with everything but the
+function async_curry (fn, fn_finish) {
+ /* We return a curried version of open_async with everything but the
* callback argument bound. Plus we pass the (curried) paired finish method as a
* property of the return value function.
*/
+ let curried_args = arguments;
+ let curried = function (cb) {
+ let args = []
+ for (let i = 2; i < curried_args.length; i++)
+ args.push (curried_args[i]);
+ args.push(cb);
+ fn.apply (this, args);
+
+ }
+ curried.finish = function(res) {
+ return open_finish (curried_args[0], res);
+ }
return curried;
}
+function $open (filename, flags) {
+ return async_curry (open_async, open_finish, filename, flags);
+}
+
/* This function lets us run a generator function as an async operation,
handling all the callbacks from the yields. You can also pass in
a callback to run when the operation is done and a list of arguments
@@ -89,18 +97,19 @@
function do_stuff2 () {
print ("do_stuff2");
- var data3 = yield open_yield ("other", 0);
+ var data3 = yield $open ("other", 0);
print ("data3 = " + data3);
print ("end of do_stuff2");
}
function do_stuff (filename1, filename2) {
print ("do_stuff");
- var data = yield open_yield (filename1, 0);
+ var data = yield $open (filename1, 0);
print ("data = " + data);
- var data2 = yield open_yield (filename2, 0);
+ var data2 = yield $open (filename2, 0);
print ("data2 = " + data2);
- yield call_async (do_stuff2);
+ var ret = yield call_async (do_stuff2);
+ print ("ret: " + ret);
print ("end of do_stuff");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]