On 10/08/2013 12:00 PM, dev-platform-requ...@lists.mozilla.org wrote:
Message: 7
Date: Tue, 8 Oct 2013 11:47:52 -0700
From: Dave Townsend <dtowns...@mozilla.com>
To: dev-platform <dev-platform@lists.mozilla.org>
Subject: Coding style for functions called by Task.jsm tasks
Message-ID:
<camqkg6svgdftpm+jy4vnoovtvw65jvqbot9zaqqa3gxlsy6...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
As Task.jsm is used more throughout our code it would be good to try to use
similar sorts of patterns to avoid confusion.
One difference I've spotted is in how to write asynchronous functions that
are called by tasks. One way is to simply write the function as a
generator, the other is to write the function as something that returns a
promise by wrapping its code with another Task.spawn call. In both cases
the calling task just yields the result of the function to wait for it to
complete.
I'm going to claim that the latter method of returning a new task promise
is the one we should use in general. It makes the function more easily
usable outside of a task since you're just getting a promise back. It is
also what Task.jsm does internally for generators anyway.
Does anyone disagree?
I usually prefer writing functions called by tasks as generators, because it
makes the code a little more readable (it avoids indentation).
It also makes the function impossible to use outside of a Task, so people in
future will not be able to just call it and forget that it's asynchronous.
If someone wanted to use the function outside of a task, they'd just need to add the
"Task wrapper".
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform