mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
This PR updates Google Apps Script types. (2017-05-12 -> 2018-07-11) This is a generated type definition. CC: @erickoledadevrel --- - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). ``` npm run lint google-apps-script definitely-typed@0.0.2 lint /Users/timmerman/Documents/github/DefinitelyTyped dtslint types "google-apps-script" # No result. ``` If changing an existing definition: - [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://developers.google.com/apps-script/reference/ - [x] Increase the version number in the header if appropriate. - The version should be bumped by the publisher. - [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
// Type definitions for Google Apps Script 2018-07-11
|
|
// Project: https://developers.google.com/apps-script/
|
|
// Definitions by: motemen <https://github.com/motemen/>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
/// <reference path="google-apps-script.types.d.ts" />
|
|
|
|
declare namespace GoogleAppsScript {
|
|
export module Lock {
|
|
/**
|
|
* A representation of a mutual-exclusion lock.
|
|
*
|
|
* This class allows scripts to make sure that only one instance of the script is executing a
|
|
* given section of code at a time. This is particularly useful for callbacks and triggers, where a
|
|
* user action may cause changes to a shared resource and you want to ensure that aren't collisions.
|
|
*
|
|
* The following examples shows how to use a lock in a form submit handler.
|
|
*
|
|
* // Generates a unique ticket number for every form submission.
|
|
* function onFormSubmit(e) {
|
|
* var targetCell = e.range.offset(0, e.range.getNumColumns(), 1, 1);
|
|
*
|
|
* // Get a script lock, because we're about to modify a shared resource.
|
|
* var lock = LockService.getScriptLock();
|
|
* // Wait for up to 30 seconds for other processes to finish.
|
|
* lock.waitLock(30000);
|
|
*
|
|
* var ticketNumber = Number(ScriptProperties.getProperty('lastTicketNumber')) + 1;
|
|
* ScriptProperties.setProperty('lastTicketNumber', ticketNumber);
|
|
*
|
|
* // Release the lock so that other processes can continue.
|
|
* lock.releaseLock();
|
|
*
|
|
* targetCell.setValue(ticketNumber);
|
|
* }
|
|
*
|
|
* lastTicketNumber
|
|
* ScriptProperties
|
|
*/
|
|
export interface Lock {
|
|
hasLock(): boolean;
|
|
releaseLock(): void;
|
|
tryLock(timeoutInMillis: Integer): boolean;
|
|
waitLock(timeoutInMillis: Integer): void;
|
|
}
|
|
|
|
/**
|
|
* Prevents concurrent access to sections of code. This can be useful when you have multiple users
|
|
* or processes modifying a shared resource and want to prevent collisions.
|
|
*/
|
|
export interface LockService {
|
|
getDocumentLock(): Lock;
|
|
getScriptLock(): Lock;
|
|
getUserLock(): Lock;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
declare var LockService: GoogleAppsScript.Lock.LockService;
|