Last active
December 18, 2019 09:06
-
-
Save scztt/16fa825fef280bea8d9b19a41fae2a4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deferred | |
( | |
// Value is not available yet, so error | |
d = Deferred(); | |
d.value.postln; | |
) | |
( | |
// Value is available | |
d = Deferred(); | |
d.value = "foo"; | |
d.value.postln; | |
) | |
( | |
// Operation resulted in an error, so rethrow when accessing value; | |
d = Deferred(); | |
d.error = Error("Something went wrong"); | |
d.value.postln; | |
) | |
( | |
// Accessing Error directly: no throw | |
d = Deferred(); | |
d.error = Error("Something went wrong"); | |
d.error.postln; | |
) | |
( | |
d = Deferred(); | |
fork { | |
var value = d.wait(); | |
value.postln; | |
}; | |
fork { | |
1.wait; | |
d.value = "Done"; | |
} | |
) | |
( | |
// Error is thrown during wait call | |
d = Deferred(); | |
fork { | |
var value = d.wait(); | |
value.postln; | |
}; | |
fork { | |
1.wait; | |
d.error = Error("oops") | |
} | |
) | |
( | |
d = Deferred(); | |
fork { | |
d.then({ | |
|value| | |
value.postln; | |
}) | |
}; | |
fork { | |
1.wait; | |
d.value = "Function style"; | |
} | |
) | |
( | |
d = Deferred(); | |
fork { | |
d.then({ | |
|value| | |
value.postln; | |
}) | |
}; | |
fork { | |
1.wait; | |
d.error = Error("Error style"); | |
} | |
) | |
( | |
d = Deferred(); | |
fork { | |
d.then({ | |
|value| | |
value.postln; | |
}, { | |
|error| | |
"Handled: %".format(error).postln; | |
}) | |
}; | |
fork { | |
1.wait; | |
d.error = Error("Error style"); | |
} | |
) | |
( | |
d = Deferred(); | |
fork { | |
d.then({ | |
|value| | |
value.postln; | |
}, { | |
|error| | |
"Handled: %".format(error).postln; | |
}) | |
}; | |
fork { | |
1.wait; | |
d.error = Error("Error style"); | |
} | |
) | |
( | |
fork { | |
// Booted server as a value | |
~deferredServer = Deferred(); | |
Server.default.waitForBoot({ | |
~deferredServer.value = Server.default; | |
}, onFailure: { | |
~deferredServer.error = Error("Server failed to boot") | |
}); | |
~deferredBuffer = Buffer.doAlloc(~deferredServer.wait, 1024); | |
~deferredBuffer.wait.sine1([1, 1, 1]); | |
SynthDef(\playit, { | |
Out.ar(0, | |
Osc.ar(~deferredBuffer.value) * Env.perc.kr(gate:1, doneAction:2) | |
) | |
}).doAdd.wait; | |
Synth(\playit); | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment