diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-10-19 01:31:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-19 01:31:14 -0400 |
commit | 175c0d56ca48cea180500931f8a44acd1ac713be (patch) | |
tree | 61ff6e3a59ae24b33037a38f67e4330baa50ba8b /tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js | |
parent | 605ddbecd4dfbbb67849cf63774b2d7635fc3601 (diff) | |
parent | aff72973cf0b2d57dc83e479d1826f4112f5d380 (diff) | |
download | servo-175c0d56ca48cea180500931f8a44acd1ac713be.tar.gz servo-175c0d56ca48cea180500931f8a44acd1ac713be.zip |
Auto merge of #24490 - servo-wpt-sync:wpt_update_18-10-2019, r=servo-wpt-sync
Sync WPT with upstream (18-10-2019)
Automated downstream sync of changes from upstream as of 18-10-2019.
[no-wpt-sync]
r? @servo-wpt-sync
Diffstat (limited to 'tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js')
-rw-r--r-- | tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js b/tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js new file mode 100644 index 00000000000..cb900605bcf --- /dev/null +++ b/tests/wpt/web-platform-tests/webgpu/framework/util/async_mutex.js @@ -0,0 +1,32 @@ +/** +* AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts +**/ + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +export class AsyncMutex { + constructor() { + _defineProperty(this, "newestQueueItem", void 0); + } + + // Run an async function with a lock on this mutex. + // Waits until the mutex is available, locks it, runs the function, then releases it. + async with(fn) { + const p = (async () => { + // If the mutex is locked, wait for the last thing in the queue before running. + // (Everything in the queue runs in order, so this is after everything currently enqueued.) + if (this.newestQueueItem) { + await this.newestQueueItem; + } + + return fn(); + })(); // Push the newly-created Promise onto the queue by replacing the old "newest" item. + + + this.newestQueueItem = p; // And return so the caller can wait on the result. + + return p; + } + +} +//# sourceMappingURL=async_mutex.js.map
\ No newline at end of file |