Send current task to server. * @param {*} [timeout=-1] Optional timeout value in ms * @returns the response from the render request. * @memberof Task
(timeout = -1)
| 887 | * @memberof Task |
| 888 | */ |
| 889 | async post(timeout = -1) { |
| 890 | performance.mark("make-render-request") |
| 891 | if (performance.getEntriesByName("click-makeImage", "mark").length > 0) { |
| 892 | performance.measure("diff", "click-makeImage", "make-render-request") |
| 893 | console.log( |
| 894 | "delay between clicking and making the server request:", |
| 895 | performance.getEntriesByName("diff", "measure")[0].duration + " ms" |
| 896 | ) |
| 897 | } |
| 898 | |
| 899 | let jsonResponse = await super.post("/render", timeout) |
| 900 | if (typeof jsonResponse?.task !== "number") { |
| 901 | console.warn("Endpoint error response: ", jsonResponse) |
| 902 | const event = Object.assign({ task: this }, jsonResponse) |
| 903 | await eventSource.fireEvent(EVENT_UNEXPECTED_RESPONSE, event) |
| 904 | if ("continueWith" in event) { |
| 905 | jsonResponse = await Promise.resolve(event.continueWith) |
| 906 | } |
| 907 | if (typeof jsonResponse?.task !== "number") { |
| 908 | const err = new Error(jsonResponse?.detail || "Endpoint response does not contains a task ID.") |
| 909 | this.abort(err) |
| 910 | throw err |
| 911 | } |
| 912 | } |
| 913 | this._setId(jsonResponse.task) |
| 914 | if (jsonResponse.stream) { |
| 915 | this.streamUrl = jsonResponse.stream |
| 916 | } |
| 917 | this._setStatus(TaskStatus.waiting) |
| 918 | return jsonResponse |
| 919 | } |
| 920 | |
| 921 | enqueue(progressCallback) { |
| 922 | return Task.enqueueNew(this, RenderTask, progressCallback) |