Skip to content

Commit

Permalink
Allow syncronous Plugin init() methods to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Aug 10, 2017
1 parent 437a12e commit 6385222
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/PluginAuthoring.md
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ class CustomPlugin extends Plugin
this.client = client;
}

async init()
init()
{
console.log('Custom plugin initialized.');
}
@@ -75,8 +75,8 @@ instance:
The Plugin `init()` method will be called when the plugin is loaded, which is after
all storages (including guild storages) are available but before `clientReady` is
emitted. Assuming you store the client instance passed in the Plugin constructor
like in the example above, you will be able to use it here. This method is expected
to be async.
like in the example above, you will be able to use it here. This method can be async
if needed to make things easier for yourself.


## Plugin tools
4 changes: 2 additions & 2 deletions src/client/Plugin.ts
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import { IPlugin } from './interface/IPlugin';
* is called
*
* <blockquote>**Note:** A plugin is expected to have two things at runtime:
* a `name` property containing the name of the plugin, and an async `init()`
* a `name` property containing the name of the plugin, and an `init()`
* method that will be called by the framework after loading the plugin.<br>
* See: {@link IPlugin#name} and {@link IPlugin#init}</blockquote>
*
@@ -42,5 +42,5 @@ import { IPlugin } from './interface/IPlugin';
export class Plugin implements IPlugin
{
public name: string;
public async init(): Promise<void> { throw new Error('Plugins must implement the `init` method'); }
public init(): void { throw new Error('Plugins must implement the `init` method'); }
}
10 changes: 6 additions & 4 deletions src/client/interface/IPlugin.ts
Original file line number Diff line number Diff line change
@@ -17,16 +17,18 @@
* @type {string}
*/
/**
* Async method that will be called by the Plugin loader when the
* Method that will be called by the Plugin loader when the
* Plugin is loaded. This is the only method that will be called by
* the framework automatically, so this should be where anything
* necessary should be done to make the Plugin operational
* necessary should be done to make the Plugin operational.
*
* > This method can be async if desired or needed
* @method IPlugin#init
* @returns {Promise<void>}
* @returns {Promise<void>|void}
*/

export interface IPlugin
{
name: string;
init(): Promise<void>;
init(): Promise<void> | void;
}

0 comments on commit 6385222

Please sign in to comment.