PageSourceSearch

https://gulpjs.com/assets/js/8c58cc34.6381fd00.js

js gulpjs.com collected 2026-09-24 07:27:47 UTC 7,113 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkgulpjs_github_io=self.webpackChunkgulpjs_github_io||[]).push([[664],{4962:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>o,contentTitle:()=>a,default:()=>h,frontMatter:()=>i,metadata:()=>l,toc:()=>c});var r=s(4848),t=s(8453);const i={id:"parallel",title:"parallel()",hide_title:!0,sidebar_label:"parallel()"},a="parallel()",l={id:"api/parallel",title:"parallel()",description:"Combines task functions and/or composed operations into larger operations that will be executed simultaneously. There are no imposed limits on the nesting depth of composed operations using series() and parallel().",source:"@site/docs/api/parallel.md",sourceDirName:"api",slug:"/api/parallel",permalink:"/docs/en/api/parallel",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{id:"parallel",title:"parallel()",hide_title:!0,sidebar_label:"parallel()"},sidebar:"docs",previous:{title:"series()",permalink:"/docs/en/api/series"},next:{title:"watch()",permalink:"/docs/en/api/watch"}},o={},c=[{value:"Usage",id:"usage",level:2},{value:"Signature",id:"signature",level:2},{value:"Parameters",id:"parameters",level:3},{value:"Returns",id:"returns",level:3},{value:"Errors",id:"errors",level:3},{value:"Forward references",id:"forward-references",level:2},{value:"Avoid duplicating tasks",id:"avoid-duplicating-tasks",level:2}];function d(e){const n={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,t.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"parallel",children:"parallel()"}),"\n",(0,r.jsxs)(n.p,{children:["Combines task functions and/or composed operations into larger operations that will be executed simultaneously. There are no imposed limits on the nesting depth of composed operations using ",(0,r.jsx)(n.code,{children:"series()"})," and ",(0,r.jsx)(n.code,{children:"parallel()"}),"."]}),"\n",(0,r.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const { parallel } = require('gulp');\n\nfunction javascript(cb) {\n  // body omitted\n  cb();\n}\n\nfunction css(cb) {\n  // body omitted\n  cb();\n}\n\nexports.build = parallel(javascript, css);\n"})}),"\n",(0,r.jsx)(n.h2,{id:"signature",children:"Signature"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"parallel(...tasks)\n"})}),"\n",(0,r.jsx)(n.h3,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{style:{textAlign:"center"},children:"parameter"}),(0,r.jsx)(n.th,{style:{textAlign:"center"},children:"type"}),(0,r.jsx)(n.th,{children:"note"})]})}),(0,r.jsx)(n.tbody,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsxs)(n.td,{style:{textAlign:"center"},children:["tasks",(0,r.jsx)("br",{}),(0,r.jsx)(n.strong,{children:"(required)"})]}),(0,r.jsxs)(n.td,{style:{textAlign:"center"},children:["function",(0,r.jsx)("br",{}),"string"]}),(0,r.jsx)(n.td,{children:"Any number of task functions can be passed as individual arguments. Strings can be used if you've registered tasks previously, but this is not recommended."})]})})]}),"\n",(0,r.jsx)(n.h3,{id:"returns",children:"Returns"}),"\n",(0,r.jsxs)(n.p,{children:["A composed operation to be registered as a task or nested within other ",(0,r.jsx)(n.code,{children:"series"})," and/or ",(0,r.jsx)(n.code,{children:"parallel"})," compositions."]}),"\n",(0,r.jsx)(n.p,{children:"When the composed operation is executed, all tasks will be run at maximum concurrency. If an error occurs in one task, other tasks nondeterministically may or may not complete."}),"\n",(0,r.jsx)(n.h3,{id:"errors",children:"Errors"}),"\n",(0,r.jsx)(n.p,{children:'When no tasks are passed, throws an error with the message, "One or more tasks should be combined using series or parallel".'}),"\n",(0,r.jsx)(n.p,{children:'When invalid tasks or unregistered tasks are passed, throws an error with the message, "Task never defined".'}),"\n",(0,r.jsx)(n.h2,{id:"forward-references",children:"Forward references"}),"\n",(0,r.jsx)(n.p,{children:"A forward reference is when you compose tasks, using string references, that haven't been registered yet. This was a common practice in older versions, but this feature was removed to achieve faster task runtime and promote the use of named functions."}),"\n",(0,r.jsxs)(n.p,{children:['In newer versions, you\'ll get an error, with the message "Task never defined", if you try to use forward references. You may experience this when trying to use ',(0,r.jsx)(n.code,{children:"exports"})," for task registration ",(0,r.jsx)(n.em,{children:"and"})," composing tasks by string. In this situation, use named functions instead of string references."]}
1),"\n",(0,r.jsxs)(n.p,{children:["During migration, you may need the ",(0,r.jsx)(n.a,{href:"https://github.com/gulpjs/undertaker-forward-reference",children:"forward reference registry"}),". This will add an extra closure to every task reference and dramatically slow down your build. ",(0,r.jsx)(n.strong,{children:"Don't rely on this fix for very long"}),"."]}),"\n",(0,r.jsx)(n.h2,{id:"avoid-duplicating-tasks",children:"Avoid duplicating tasks"}),"\n",(0,r.jsx)(n.p,{children:"When a composed operation is run, each task will be executed every time it was supplied."}),"\n",(0,r.jsxs)(n.p,{children:["A ",(0,r.jsx)(n.code,{children:"clean"})," task referenced in two different compositions would be run twice and lead to undesired results. Instead, refactor the ",(0,r.jsx)(n.code,{children:"clean"})," task to be specified in the final composition."]}),"\n",(0,r.jsx)(n.p,{children:"If you have code like this:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"// This is INCORRECT\nconst { series, parallel } = require('gulp');\n\nconst clean = function(cb) {\n  // body omitted\n  cb();\n};\n\nconst css = series(clean, function(cb) {\n  // body omitted\n  cb();\n});\n\nconst javascript = series(clean, function(cb) {\n  // body omitted\n  cb();\n});\n\nexports.build = parallel(css, javascript);\n"})}),"\n",(0,r.jsx)(n.p,{children:"Migrate to this:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const { series, parallel } = require('gulp');\n\nfunction clean(cb) {\n  // body omitted\n  cb();\n}\n\nfunction css(cb) {\n  // body omitted\n  cb();\n}\n\nfunction javascript(cb) {\n  // body omitted\n  cb();\n}\n\nexports.build = series(clean, parallel(css, javascript));\n"})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>a,x:()=>l});var r=s(6540);const t={},i=r.createContext(t);function a(e){const n=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(i.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.