Skip to content

How to use cork properly? #1092

Closed Answered by dalisoft
dalisoft asked this question in Q&A
Aug 13, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Used another approach and it's more efficient in terms of response but performance may be not the fastest

Batch cork

app.get('/cork', async (res) => {
  const corks = [];
  
  corks.push(() => {
    res.writeStatus('301 Moved Permanently');
  });
  corks.push(() => {
    res.writeHeader('Content-Type', 'application/text');
  });
  corks.push(() => {
    res.end('success');
  });
  
  return res.cork(() => {
    for (const cork of corks) {
      cork();
    }
  });
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by dalisoft
Comment options

You must be logged in to vote
1 reply
@dalisoft
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants