# Wrapping synchronous Buffer operations in a function

**URL:** <https://discourse.flucoma.org/t/wrapping-synchronous-buffer-operations-in-a-function/1049>\
**Category:** Usage Questions\
**Created:** [November 1, 2021, 9:16pm UTC](https://discourse.flucoma.org/t/wrapping-synchronous-buffer-operations-in-a-function/1049 "2021-11-01T21:16:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![weefuzzy](https://discourse.flucoma.org/user_avatar/discourse.flucoma.org/weefuzzy/32/362_2.png) [@weefuzzy](https://discourse.flucoma.org/u/weefuzzy)\
**Post date:** [November 1, 2021, 10:40pm UTC](https://discourse.flucoma.org/t/wrapping-synchronous-buffer-operations-in-a-function/1049/2 "2021-11-01T22:40:04Z")

</div>

Welcome @heretogo , thanks for your question!

Do you mean you’d like to have the function return as if it were a synchronous function in the main thread? I don’t think it can be done without running the whole thing in a `Routine ` or similar, because the processing and buffer fetching from the server are both asynchronous, so you need to make things block.

```auto
(
~getFrequencies = {|in|
    var out; 
    var cond = Condition.new; 
    var outBuf = Buffer.new; 
    FluidBufPitch.process(s, in, features: outBuf,
        action:{outBuf.loadToFloatArray(
            action: {|x| 
                out = x.reshape((x.size()/2).asInteger, 2); 
                cond.unhang; 
            }
        )
        }
    );
    cond.hang; 
    out
};

fork{   
    b = Buffer.read(s, File.realpath(FluidBufPitch.class.filenameSymbol).dirname.withTrailingSlash ++ "../AudioFiles/Tremblay-ASWINE-ScratchySynth-M.wav");
    s.sync;  
    ~getFrequencies.value(b).postln; 
}
)

```

---

_[View the full topic](https://discourse.flucoma.org/t/wrapping-synchronous-buffer-operations-in-a-function/1049)._
