Closed Bug 1329116 Opened 7 years ago Closed 7 years ago

Update TelemetryEnvironment.jsm to async function & await

Categories

(Toolkit :: Telemetry, defect, P4)

defect

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: gfritzsche, Assigned: djmdeveloper060796, Mentored)

References

Details

(Whiteboard: [measurement:client] [lang=js])

Attachments

(1 file, 4 obsolete files)

We have `async function` and `await` now:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

We should be able to switch all of the `Task.async`, `Task.spawn` and `function*` uses over to those:
https://dxr.mozilla.org/mozilla-central/search?q=path%3Atoolkit%2Fcomponents%2Ftelemetry%2F+ext%3Ajs+ext%3Ajsm+Task.&redirect=false

The only case i can think of that doesn't migrate trivially is the `DeferredTask` usage, we could just leave that one for now.
I would be happy to mentor this. Note though that this isn't a good first bug.

Changes can be checked against our unit tests using:
mach xpcshell-test toolkit/components/telemetry/tests/unit

To start with a smaller change, you can make changes to e.g. only TelemetryEnvironment.jsm and run only the test for that:
mach xpcshell-test toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.jsm

After the tests runs through fine, we also need to manually test by running the Firefox build:
- check that pings are still generated as expected on e.g. addon installs, using about:telemetry
- sent out successfully, using https://github.com/mozilla/gzipServer
- no new errors related to our code should show up in the browser console
Mentor: alessio.placitelli, gfritzsche
Whiteboard: [measurement:client] → [measurement:client] [lang=js]
Hi Georg! I have taken up a few good first bugs till now. I would like to take this up. Can you please assign it to me and help me get started with this?
Flags: needinfo?(gfritzsche)
Sure - the relevant information is in comment 0 & comment 1. We want to get rid of the mentioned `Task.*` and `function*` uses and instead use `async` & `await` instead.

As mentioned, i really recommend starting with only the TelemetryEnvironment files to see how it works.
Let us know if you run into any problems or have questions.
Flags: needinfo?(gfritzsche)
Attached patch bug1329116.patch (obsolete) — Splinter Review
I am trying to solve this issue. I have started with the TelemetryEnvironment.jsm file. I am facing some problems.

I have changed Task.async(function*() { /*stuff*/ }) to 
async function() { /*stuff*/ }

however I am getting the following error (below attached file)
Attached file error_test.text (obsolete) —
Flags: needinfo?(gfritzsche)
The actual error line is:
> ERROR SyntaxError: yield is a reserved identifier at resource://gre/modules/TelemetryEnvironment.jsm:530

This is because `yield` is only allowed in generator functions [1], which were used with Task.async() etc. to wait on promises.
With the change you did, you need to use `await` instead of `yield`.
Flags: needinfo?(gfritzsche)
To reduce the scope of this bug, i'm limiting this to only changing TelemetryEnvironment.jsm.
Summary: Update Telemetry JS modules to async function & await → Update Telemetry environment module to async function & await
Summary: Update Telemetry environment module to async function & await → Update TelemetryEnvironment.jsm to async function & await
Blocks: 1344733
Assignee: nobody → djmdeveloper060796
Attached patch bug1329116.patch (obsolete) — Splinter Review
I have changed yield to await, now there is no more errors
Attachment #8843683 - Attachment is obsolete: true
Attachment #8843687 - Attachment is obsolete: true
Attachment #8844321 - Flags: review?(gfritzsche)
Comment on attachment 8844321 [details] [diff] [review]
bug1329116.patch

Review of attachment 8844321 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks! This looks good, with the eslint error below fixed.

Lets also remove the import for Task.jsm at the start of the file. With the changes here it is no longer needed.

::: toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ +516,4 @@
>     *   changed - Whether the environment changed.
>     *   oldEnvironment - Only set if a change occured, contains the environment data before the change.
>     */
> +  _updateAddons: async function() {

Please make sure to fix the eslint errors, e.g. from running:
./mach eslint toolkit/components/telemetry/

This can now use the shorthand async method definitions:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions#Shorthand_async_methods
Attachment #8844321 - Flags: review?(gfritzsche) → feedback+
Attached patch bug1329116.patch (obsolete) — Splinter Review
Removed the eslint error
Attachment #8844321 - Attachment is obsolete: true
Attachment #8844942 - Flags: review?(gfritzsche)
Attached patch bug1329116.patchSplinter Review
fixed eslint errors and removed the import statement for Task.jsm
Attachment #8844942 - Attachment is obsolete: true
Attachment #8844942 - Flags: review?(gfritzsche)
Attachment #8844994 - Flags: review?(gfritzsche)
Comment on attachment 8844994 [details] [diff] [review]
bug1329116.patch

Review of attachment 8844994 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks, this looks good!
Attachment #8844994 - Flags: review?(gfritzsche) → review+
I've run the tests locally, this should be good to land.
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4c2eaf534ed7
Update TelemetryEnvironment.jsm to async function & await. r=gfritzsche
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/4c2eaf534ed7
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: