how to call multiple operations at the same time
I know I can use GCD or an OperationQueue to do concurrent workload but I've been trying to look for a way to call multiple functions and have them start at the same time.
My project here is to trigger multiple webcams at once to have synchronised photos coming from different cameras.
I had found this post about how to display multiple feeds from multiple webcams at once here: Run multiple AVCaptureSessions or add multiple inputs
I am unsure of how I will be able to trigger a photo capture from these as of yet, but I first wanted to see how I would go about synchronising the call to the function.
My theoretical solution would be something like this:
- create concurrent operation queue
- make it so I can start the operation queue manually rather than start each operation automatically as it would be added to the queue (how ?)
- add an operation that would take a picture from the associated video input. Once for each camera
- start operation queue
- wait for operations to finish
- continue workflow
Is this possible ?
If not is calling multiple methods truly at once even possible ?
If even this isn't possible how would I go about synchronising the photo capture, maybe recording a short video, use timestamp right before the start of the recording to adjust delay and capture frames at a specific time in the resulting videos ?
Also in the comments, what is the tag for a MacOS application built in swift ? It's my first time asking for this rather than iOS so it would help find people who might be able to help.
Thanks for any insight you might be able to give me !
swift macos
add a comment |
I know I can use GCD or an OperationQueue to do concurrent workload but I've been trying to look for a way to call multiple functions and have them start at the same time.
My project here is to trigger multiple webcams at once to have synchronised photos coming from different cameras.
I had found this post about how to display multiple feeds from multiple webcams at once here: Run multiple AVCaptureSessions or add multiple inputs
I am unsure of how I will be able to trigger a photo capture from these as of yet, but I first wanted to see how I would go about synchronising the call to the function.
My theoretical solution would be something like this:
- create concurrent operation queue
- make it so I can start the operation queue manually rather than start each operation automatically as it would be added to the queue (how ?)
- add an operation that would take a picture from the associated video input. Once for each camera
- start operation queue
- wait for operations to finish
- continue workflow
Is this possible ?
If not is calling multiple methods truly at once even possible ?
If even this isn't possible how would I go about synchronising the photo capture, maybe recording a short video, use timestamp right before the start of the recording to adjust delay and capture frames at a specific time in the resulting videos ?
Also in the comments, what is the tag for a MacOS application built in swift ? It's my first time asking for this rather than iOS so it would help find people who might be able to help.
Thanks for any insight you might be able to give me !
swift macos
add a comment |
I know I can use GCD or an OperationQueue to do concurrent workload but I've been trying to look for a way to call multiple functions and have them start at the same time.
My project here is to trigger multiple webcams at once to have synchronised photos coming from different cameras.
I had found this post about how to display multiple feeds from multiple webcams at once here: Run multiple AVCaptureSessions or add multiple inputs
I am unsure of how I will be able to trigger a photo capture from these as of yet, but I first wanted to see how I would go about synchronising the call to the function.
My theoretical solution would be something like this:
- create concurrent operation queue
- make it so I can start the operation queue manually rather than start each operation automatically as it would be added to the queue (how ?)
- add an operation that would take a picture from the associated video input. Once for each camera
- start operation queue
- wait for operations to finish
- continue workflow
Is this possible ?
If not is calling multiple methods truly at once even possible ?
If even this isn't possible how would I go about synchronising the photo capture, maybe recording a short video, use timestamp right before the start of the recording to adjust delay and capture frames at a specific time in the resulting videos ?
Also in the comments, what is the tag for a MacOS application built in swift ? It's my first time asking for this rather than iOS so it would help find people who might be able to help.
Thanks for any insight you might be able to give me !
swift macos
I know I can use GCD or an OperationQueue to do concurrent workload but I've been trying to look for a way to call multiple functions and have them start at the same time.
My project here is to trigger multiple webcams at once to have synchronised photos coming from different cameras.
I had found this post about how to display multiple feeds from multiple webcams at once here: Run multiple AVCaptureSessions or add multiple inputs
I am unsure of how I will be able to trigger a photo capture from these as of yet, but I first wanted to see how I would go about synchronising the call to the function.
My theoretical solution would be something like this:
- create concurrent operation queue
- make it so I can start the operation queue manually rather than start each operation automatically as it would be added to the queue (how ?)
- add an operation that would take a picture from the associated video input. Once for each camera
- start operation queue
- wait for operations to finish
- continue workflow
Is this possible ?
If not is calling multiple methods truly at once even possible ?
If even this isn't possible how would I go about synchronising the photo capture, maybe recording a short video, use timestamp right before the start of the recording to adjust delay and capture frames at a specific time in the resulting videos ?
Also in the comments, what is the tag for a MacOS application built in swift ? It's my first time asking for this rather than iOS so it would help find people who might be able to help.
Thanks for any insight you might be able to give me !
swift macos
swift macos
edited Nov 16 '18 at 1:43
James Woodrow
asked Nov 16 '18 at 1:31
James WoodrowJames Woodrow
1309
1309
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are on the right track (NS)OperationQueue
is made for this. Below is an example:
func operation1()
print("(#function) starts")
sleep(1)
print("(#function) ends")
func operation2()
print("(#function) starts")
sleep(2)
print("(#function) ends")
func operation3()
print("(#function) starts")
sleep(3)
print("(#function) ends")
@IBAction func start(_ sender: Any)
let operation = BlockOperation(block: )
operation.addExecutionBlock self.operation1()
operation.addExecutionBlock self.operation2()
operation.addExecutionBlock self.operation3()
let endOperation = BlockOperation self.allFinished()
endOperation.addDependency(operation)
let queue = OperationQueue()
queue.addOperations([operation, endOperation], waitUntilFinished: false)
func allFinished()
print("all finished")
operation1, 2, 3
can start in arbitrary order but the finishing order is always 1, 2, 3, and then allFinished
is triggered.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330203%2fhow-to-call-multiple-operations-at-the-same-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are on the right track (NS)OperationQueue
is made for this. Below is an example:
func operation1()
print("(#function) starts")
sleep(1)
print("(#function) ends")
func operation2()
print("(#function) starts")
sleep(2)
print("(#function) ends")
func operation3()
print("(#function) starts")
sleep(3)
print("(#function) ends")
@IBAction func start(_ sender: Any)
let operation = BlockOperation(block: )
operation.addExecutionBlock self.operation1()
operation.addExecutionBlock self.operation2()
operation.addExecutionBlock self.operation3()
let endOperation = BlockOperation self.allFinished()
endOperation.addDependency(operation)
let queue = OperationQueue()
queue.addOperations([operation, endOperation], waitUntilFinished: false)
func allFinished()
print("all finished")
operation1, 2, 3
can start in arbitrary order but the finishing order is always 1, 2, 3, and then allFinished
is triggered.
add a comment |
You are on the right track (NS)OperationQueue
is made for this. Below is an example:
func operation1()
print("(#function) starts")
sleep(1)
print("(#function) ends")
func operation2()
print("(#function) starts")
sleep(2)
print("(#function) ends")
func operation3()
print("(#function) starts")
sleep(3)
print("(#function) ends")
@IBAction func start(_ sender: Any)
let operation = BlockOperation(block: )
operation.addExecutionBlock self.operation1()
operation.addExecutionBlock self.operation2()
operation.addExecutionBlock self.operation3()
let endOperation = BlockOperation self.allFinished()
endOperation.addDependency(operation)
let queue = OperationQueue()
queue.addOperations([operation, endOperation], waitUntilFinished: false)
func allFinished()
print("all finished")
operation1, 2, 3
can start in arbitrary order but the finishing order is always 1, 2, 3, and then allFinished
is triggered.
add a comment |
You are on the right track (NS)OperationQueue
is made for this. Below is an example:
func operation1()
print("(#function) starts")
sleep(1)
print("(#function) ends")
func operation2()
print("(#function) starts")
sleep(2)
print("(#function) ends")
func operation3()
print("(#function) starts")
sleep(3)
print("(#function) ends")
@IBAction func start(_ sender: Any)
let operation = BlockOperation(block: )
operation.addExecutionBlock self.operation1()
operation.addExecutionBlock self.operation2()
operation.addExecutionBlock self.operation3()
let endOperation = BlockOperation self.allFinished()
endOperation.addDependency(operation)
let queue = OperationQueue()
queue.addOperations([operation, endOperation], waitUntilFinished: false)
func allFinished()
print("all finished")
operation1, 2, 3
can start in arbitrary order but the finishing order is always 1, 2, 3, and then allFinished
is triggered.
You are on the right track (NS)OperationQueue
is made for this. Below is an example:
func operation1()
print("(#function) starts")
sleep(1)
print("(#function) ends")
func operation2()
print("(#function) starts")
sleep(2)
print("(#function) ends")
func operation3()
print("(#function) starts")
sleep(3)
print("(#function) ends")
@IBAction func start(_ sender: Any)
let operation = BlockOperation(block: )
operation.addExecutionBlock self.operation1()
operation.addExecutionBlock self.operation2()
operation.addExecutionBlock self.operation3()
let endOperation = BlockOperation self.allFinished()
endOperation.addDependency(operation)
let queue = OperationQueue()
queue.addOperations([operation, endOperation], waitUntilFinished: false)
func allFinished()
print("all finished")
operation1, 2, 3
can start in arbitrary order but the finishing order is always 1, 2, 3, and then allFinished
is triggered.
answered Nov 20 '18 at 2:54
Code DifferentCode Different
48.7k878114
48.7k878114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330203%2fhow-to-call-multiple-operations-at-the-same-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown