{"id":405718,"date":"2024-06-29T18:29:51","date_gmt":"2024-06-29T18:29:51","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=405718"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=405718","title":{"rendered":"<span>\u041d\u043e\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0432 TypeScript 5.2<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <strong>Matt Pocock<\/strong>.<br \/><a href=\"https:\/\/www.totaltypescript.com\/typescript-5-2-new-keyword-using\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a><\/p>\n<p>TypeScript 5.2 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e &#8212; <code>using<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Symbol.dispose<\/code>, \u043f\u0440\u0438 \u043f\u043e\u043a\u0438\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code>{   const getResource = () => {     return {       [Symbol.dispose]: () => {         console.log('Hooray!')       }     }   }   using resource = getResource(); } \/\/ 'Hooray!' logged to console<\/code><\/pre>\n<p>\u041e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u044d\u0442\u043e <a href=\"https:\/\/github.com\/tc39\/proposal-explicit-resource-management\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 TC39<\/u><\/a>, \u0434\u043e\u0441\u0442\u0438\u0433\u0448\u0438\u043c\u0438 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0424\u0430\u0437\u044b 3, \u0447\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 JavaScript.<\/p>\n<p><code>using<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442  \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442.\u043f.<\/p>\n<h3>Symbol.dispose<\/h3>\n<p><code>Symbol.dispose<\/code>\u00a0&#8212; \u043d\u043e\u0432\u044b\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 JavaScript. \u0412\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439,  \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u043e\u0439<code>Symbol.dispose<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a &#8216;\u0440\u0435\u0441\u0443\u0440\u0441&#8217; &#8212;\u00a0<a href=\"https:\/\/github.com\/tc39\/proposal-explicit-resource-management#definitions\" rel=\"noopener noreferrer nofollow\"><u>&#171;\u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0441\u043e\u0431\u044b\u043c \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c&#187;<\/u><\/a>\u00a0&#8212; \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u043e \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<code>using<\/code>.<\/p>\n<pre><code>const resource = {   [Symbol.dispose]: () => {     console.log(\"Hooray!\");   }, };<\/code><\/pre>\n<h3>await using<\/h3>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<code>Symbol.asyncDispose<\/code>\u00a0\u0438\u00a0<code>await using<\/code>\u00a0\u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<pre><code>const getResource = () => ({   [Symbol.asyncDispose]: async () => {     await someAsyncFunc();   }, }); {   await using resource = getResource(); }<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>Symbol.asyncDispose<\/code>\u00a0\u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0411\u0414, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c.<\/p>\n<h2>\u0421\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<h2>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b<\/h2>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u043e\u0432 \u043d\u0430 \u043d\u043e\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0441 <code>using<\/code>.<\/p>\n<p>\u0414\u043e:<\/p>\n<pre><code>import { open } from \"node:fs\/promises\"; let filehandle; try {   filehandle = await open(\"thefile.txt\", \"r\"); } finally {   await filehandle?.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435:<\/p>\n<pre><code>import { open } from \"node:fs\/promises\"; const getFileHandle = async (path: string) => {   const filehandle = await open(path, \"r\");   return {     filehandle,     [Symbol.asyncDispose]: async () => {       await filehandle.close();     },   }; }; {   await using file = getFileHandle(\"thefile.txt\");   \/\/ Do stuff with file.filehandle } \/\/ Automatically disposed!<\/code><\/pre>\n<h2>\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0411\u0414<\/h2>\n<p>\u0414\u043e:<\/p>\n<pre><code>const connection = await getDb(); try {   \/\/ Do stuff with connection } finally {   await connection.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435:<\/p>\n<pre><code>const getConnection = async () => {   const connection = await getDb();   return {     connection,     [Symbol.asyncDispose]: async () => {       await connection.close();     },   }; }; {   await using { connection } = getConnection();   \/\/ Do stuff with connection } \/\/ Automatically closed!<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0411\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043f\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0443 &#8212; <a href=\"https:\/\/t.me\/+EAmh9cH1KNkxNjNi\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745514\/\"> https:\/\/habr.com\/ru\/articles\/745514\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <strong>Matt Pocock<\/strong>.<br \/><a href=\"https:\/\/www.totaltypescript.com\/typescript-5-2-new-keyword-using\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a><\/p>\n<p>TypeScript 5.2 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e &#8212; <code>using<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Symbol.dispose<\/code>, \u043f\u0440\u0438 \u043f\u043e\u043a\u0438\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code>{   const getResource = () => {     return {       [Symbol.dispose]: () => {         console.log('Hooray!')       }     }   }   using resource = getResource(); } \/\/ 'Hooray!' logged to console<\/code><\/pre>\n<p>\u041e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u044d\u0442\u043e <a href=\"https:\/\/github.com\/tc39\/proposal-explicit-resource-management\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 TC39<\/u><\/a>, \u0434\u043e\u0441\u0442\u0438\u0433\u0448\u0438\u043c\u0438 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0424\u0430\u0437\u044b 3, \u0447\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 JavaScript.<\/p>\n<p><code>using<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442  \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442.\u043f.<\/p>\n<h3>Symbol.dispose<\/h3>\n<p><code>Symbol.dispose<\/code>\u00a0&#8212; \u043d\u043e\u0432\u044b\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 JavaScript. \u0412\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439,  \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u043e\u0439<code>Symbol.dispose<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a &#8216;\u0440\u0435\u0441\u0443\u0440\u0441&#8217; &#8212;\u00a0<a href=\"https:\/\/github.com\/tc39\/proposal-explicit-resource-management#definitions\" rel=\"noopener noreferrer nofollow\"><u>&#171;\u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0441\u043e\u0431\u044b\u043c \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c&#187;<\/u><\/a>\u00a0&#8212; \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u043e \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<code>using<\/code>.<\/p>\n<pre><code>const resource = {   [Symbol.dispose]: () => {     console.log(\"Hooray!\");   }, };<\/code><\/pre>\n<h3>await using<\/h3>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<code>Symbol.asyncDispose<\/code>\u00a0\u0438\u00a0<code>await using<\/code>\u00a0\u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<pre><code>const getResource = () => ({   [Symbol.asyncDispose]: async () => {     await someAsyncFunc();   }, }); {   await using resource = getResource(); }<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>Symbol.asyncDispose<\/code>\u00a0\u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0411\u0414, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c.<\/p>\n<h2>\u0421\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<h2>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b<\/h2>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u043e\u0432 \u043d\u0430 \u043d\u043e\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0441 <code>using<\/code>.<\/p>\n<p>\u0414\u043e:<\/p>\n<pre><code>import { open } from \"node:fs\/promises\"; let filehandle; try {   filehandle = await open(\"thefile.txt\", \"r\"); } finally {   await filehandle?.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435:<\/p>\n<pre><code>import { open } from \"node:fs\/promises\"; const getFileHandle = async (path: string) => {   const filehandle = await open(path, \"r\");   return {     filehandle,     [Symbol.asyncDispose]: async () => {       await filehandle.close();     },   }; }; {   await using file = getFileHandle(\"thefile.txt\");   \/\/ Do stuff with file.filehandle } \/\/ Automatically disposed!<\/code><\/pre>\n<h2>\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0411\u0414<\/h2>\n<p>\u0414\u043e:<\/p>\n<pre><code>const connection = await getDb(); try {   \/\/ Do stuff with connection } finally {   await connection.close(); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435:<\/p>\n<pre><code>const getConnection = async () => {   const connection = await getDb();   return {     connection,     [Symbol.asyncDispose]: async () => {       await connection.close();     },   }; }; {   await using { connection } = getConnection();   \/\/ Do stuff with connection } \/\/ Automatically closed!<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0411\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043f\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0443 &#8212; <a href=\"https:\/\/t.me\/+EAmh9cH1KNkxNjNi\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/745514\/\"> https:\/\/habr.com\/ru\/articles\/745514\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-405718","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=405718"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/405718\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=405718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=405718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=405718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}